Code Monkey home page Code Monkey logo

ansible-junos-stdlib's Introduction

Documentation Status

Juniper Ansible collection for Junos

About

Juniper Networks supports Ansible for managing devices running the Junos operating system (Junos OS and Junos Evolved). This collection is hosted on the Ansible Galaxy website under the collection juniper.device.

The juniper.device collection includes a set of Ansible modules that perform specific operational and configuration tasks on devices running Junos OS. These tasks include: installing and upgrading Junos OS, provisioning new Junos devices in the network, loading configuration changes, retrieving information, and resetting, rebooting, or shutting down managed devices. Please refer to the INSTALLATION section for instructions on installing this collection.

Two Sets of Ansible Modules for Junos devices

Since Ansible version >= 2.1, Ansible also natively includes core modules for Junos. The Junos modules included in Ansible core have names which begin with the prefix junos_. The Junos modules included in this Juniper.device collection have names starting with module types. These two sets of Junos modules can coexist on the same Ansible control machine, and an Ansible playbook may invoke a module from either (or both) sets. Juniper Networks recommends using the modules in juniper.device collection when writing new playbooks that manage Junos devices.

Overview of Modules

This juniper.device collection includes the following modules:

  • command — Execute one or more CLI commands on a Junos device.
  • config — Manipulate the configuration of a Junos device.
  • facts — Retrieve facts from a Junos device.
  • file_copy - Copy the files from and to a Junos device.
  • jsnapy — Execute JSNAPy tests on a Junos device.
  • ping — Execute ping from a Junos device.
  • pmtud — Perform path MTU discovery from a Junos device to a destination.
  • rpc — Execute one or more NETCONF RPCs on a Junos device.
  • software — Install software on a Junos device.
  • srx_cluster — Add or remove SRX chassis cluster configuration.
  • system — Initiate operational actions on the Junos system.
  • table — Retrieve data from a Junos device using a PyEZ table/view.

PyEZ Version Requirement

For ansible collection juniper.device we will need to install junos-eznc version 2.6.0 or higher.

Overview of Plugins

In addition to the modules listed above, a callback_plugin jsnapy is available for the module jsnapy.

The callback_plugin jsnapy helps to print on the screen additional information regarding jsnapy failed tests. For each failed test, a log will be printed after the RECAP of the playbook as shown in this example:

PLAY RECAP *********************************************************************
qfx10002-01                : ok=3    changed=0    unreachable=0    failed=1
qfx10002-02                : ok=3    changed=0    unreachable=0    failed=1
qfx5100-01                 : ok=1    changed=0    unreachable=0    failed=1

JSNAPy Results for: qfx10002-01 ************************************************
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "60021", "peer-state": "Idle", "peer-address": "192.168.0.1"}
Value of 'oper-status' not 'is-equal' at '//interface-information/physical-interface[normalize-space(admin-status)='up' and logical-interface/address-family/address-family-name ]' with {"oper-status": "down", "name": "et-0/0/18"}

JSNAPy Results for: qfx10002-02 ************************************************
Value of 'peer-state' not 'is-equal' at '//bgp-information/bgp-peer' with {"peer-as": "65200", "peer-state": "Active", "peer-address": "100.0.0.21"}

Callback plugins are not activated by default. They must be manually added to the Ansible configuration file under the [defaults] section using the variable callback_whitelist. Specifically, these lines should be added to the Ansible configuration file in order to allow the jsnapy callback plugin:

[defaults]
callback_whitelist = jsnapy

DOCUMENTATION

Official Juniper documentation (detailed information, including examples)

Ansible style documentation

INSTALLATION

You must have the DEPENDENCIES installed on your system. Check requirements.txt for the dependencies.

NOTICES

MacOS Mojave and newer

In MacOS Mojave and newer (>=10.14), ssh keys created with the system ssh-keygen are created using the newer 'OPENSSH' key format, even when specifying -t rsa during creation. This directly affects the usage of ssh keys, particularly when using the ssh_private_key_file. To create/convert/check keys, follow these steps:

  • Create a new RSA key: ssh-keygen -m PEM -t rsa -b 4096
  • Check existing keys: head -n1 ~/.ssh/some_private_key RSA keys will be -----BEGIN RSA PRIVATE KEY----- and OPENSSH keys will be -----BEGIN OPENSSH PRIVATE KEY-----
  • Convert an OPENSSH key to an RSA key: ssh-keygen -p -m PEM -f ~/.ssh/some_key

Ansible Galaxy collection

You can use the ansible-galaxy install command to install the latest version of the juniper.device collection.

sudo ansible-galaxy collection install juniper.device

You can also use the ansible-galaxy install command to install the latest development version of the junos collections directly from GitHub.

sudo ansible-galaxy collection install git+https://github.com/Juniper/ansible-junos-stdlib.git#/ansible_collections/juniper/device

For more information visit - https://docs.ansible.com/ansible/latest/user_guide/collections_using.html#specifying-the-location-to-search-for-collections

Git clone

For testing you can git clone this repo and run the env-setup script in the repo directory:

user@ansible-junos-stdlib> source env-setup

This will set your $ANSIBLE_LIBRARY variable to the repo location and the installed Ansible library path. For example:

$ echo $ANSIBLE_LIBRARY /home/jeremy/Ansible/ansible-junos-stdlib/library:/usr/share/ansible

Docker

To run this as a Docker container, which includes JSNAPy and PyEZ, simply pull it from the Docker hub and run it. The following will pull the latest image and run it in an interactive ash shell.

docker run -it --rm juniper/pyez-ansible

Although, you'll probably want to bind mount a host directory (perhaps the directory containing your playbooks and associated files). The following will bind mount the current working directory and start the ash shell.

docker run -it --rm -v $PWD:/project juniper/pyez-ansible

You can also use the container as an executable to run your playbooks. Let's assume we have a typical playbook structure as below:

example
|playbook.yml
|hosts
|-vars
|-templates
|-scripts

We can move to the example directory and run the playbook with the following command:

cd example/ docker run -it --rm -v $PWD:/playbooks juniper/pyez-ansible ansible-playbook -i hosts playbook.yml

You can pass any valid command string after the container name and it will be passed to Bash for execution.

You may have noticed that the base command is almost always the same. We can also use an alias to save some keystrokes.

alias pb-ansible="docker run -it --rm -v $PWD:/project juniper/pyez-ansible ansible-playbook" pb-ansible -i hosts playbook.yml

Extending the container with additional packages

It's possible to install additional OS (Alpine) packages, Python packages (via pip), and Ansible collections at container instantiation. This can be done by passing in environment variables or binding mount files.

OS Packages

Environment Variable: $APK Bind Mount: /extras/apk.txt File Format: list of valid Alpine packages, one per line Examples:

As an environment variable, where the file containing a list of packages is in the current directory.

docker run -it --rm -v $PWD:/project -e APK="apk.txt" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/apk.txt:/extras/apk.txt juniper/pyez-ansible

Python Packages

Environment Variable: $REQ Bind Mount: /extras/requirements.txt File Format: pip requirements file

Examples:

docker run -it --rm -v $PWD:/project -e REQ="requirements.txt" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/requirements.txt:/extras/requirements.txt juniper/pyez-ansible

Ansible Packages

Environment Variable: $ROLES Bind Mount: /extras/requirements.yml File Format: Ansible requirements file

NOTE: This works for collections as well as roles.

Examples:

docker run -it --rm -v $PWD:/project -e REQ="requirements.yml" juniper/pyez-ansible

As a bind mount.

docker run -it --rm -v $PWD/requirements.txt:/extras/requirements.yml juniper/pyez-ansible

Example Playbook

This example outlines how to use Ansible to install or upgrade the software image on a device running Junos OS.

---
- name: Install Junos OS
  hosts: dc1
  connection: local
  gather_facts: false
  vars:
    wait_time: 3600
    pkg_dir: /var/tmp/junos-install
    os_version: 14.1R1.10
    os_package: jinstall-14.1R1.10-domestic-signed.tgz
    log_dir: /var/log/ansible

  tasks:
    - name: Checking NETCONF connectivity
      ansible.builtin.wait_for:
        host: "{{ inventory_hostname }}"
        port: 830
        timeout: 5
    - name: Install Junos OS package
      juniper.device.software:
        reboot: true
        version: "{{ os_version }}"
        package: "{{ pkg_dir }}/{{ os_package }}"
        logfile: "{{ log_dir }}/software.log"
      register: sw
      notify:
        - Wait_reboot

  handlers:
    - name: Wait_reboot
      ansible.builtin.wait_for:
        host: "{{ inventory_hostname }}"
        port: 830
        timeout: "{{ wait_time }}"
      when: not sw.check_mode

DEPENDENCIES

This modules requires the following to be installed on the Ansible control machine:

LICENSE

Apache 2.0

SUPPORT

Support for this juniper.device collection is provided by the community and Juniper Networks. If you have an issue with a module in the juniper.device collection, you may:

Support for the Junos modules included in Ansible core is provided by Ansible. If you have an issue with an Ansible core module you should open a Github issue against the Ansible project.

CONTRIBUTORS

Juniper Networks is actively contributing to and maintaining this repo. Please contact [email protected] for any queries.

Contributors: Stephen Steiner, Dinesh Babu, Chidanand Pujar

Former Contributors:

Stacy W Smith, Jeremy Schulman, Rick Sherman, Damien Garros, David Gethings, Nitin Kumar, Rahul Kumar

ansible-junos-stdlib's People

Contributors

apurvaraghu avatar bhundven avatar chepazzo avatar chidanandpujar avatar chientingchen avatar dgarros avatar dgjnpr avatar dineshbaburam91 avatar isometry avatar jbain avatar jedelman8 avatar jeremyschulman avatar jorgebonilla avatar jpvrenen avatar kr3ator avatar mkomon avatar ntwrkguru avatar panks21 avatar r2600r avatar rahkumar651991 avatar routenull0 avatar rsmekala avatar shermdog avatar ssawtell avatar stacywsmith avatar vnitinv avatar xionox avatar ydnath avatar ymitsos avatar yurilaaziz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-junos-stdlib's Issues

<junos_install_config> "exceptions.ValueError " Error when using overwrite with set file.

regress@vm-nomadic-ubuntu:/usr/local/junos/log$ tail -f config.log
2014-05-30 09:14:48,197:CONFIG:triplane:connecting to host: regress@triplane
2014-05-30 09:14:55,017:CONFIG:triplane:pushing file: /usr/local/junos/config/only_policy.set
2014-05-30 09:14:55,017:CONFIG:triplane:taking lock
2014-05-30 09:14:55,081:CONFIG:triplane:loading config
2014-05-30 09:14:55,762:CONFIG:triplane:committing change, please be patient
2014-05-30 09:15:06,353:CONFIG:triplane:unlocking
2014-05-30 09:15:06,468:CONFIG:triplane:change completed
2014-05-30 09:18:24,603:CONFIG:triplane:connecting to host: regress@triplane
2014-05-30 09:18:30,883:CONFIG:triplane:pushing file: /usr/local/junos/config/triplane_noprotect.set
2014-05-30 09:18:30,883:CONFIG:triplane:taking lock
2014-05-30 09:18:30,998:CONFIG:triplane:loading config
2014-05-30 09:18:30,998:CONFIG:triplane:'exceptions.ValueError' object has no attribute 'rsp'

Via Juniper/py-junos-eznc#232

Can't Specify SSH Key

Specifying an SSH key with Ansible is not honored by the Juniper module. With the key loaded to the device, the following error occurs:

TASK: [Deploying Configuration] ***********************************************
failed: [cs01.hq.adap.tv] => {"failed": true}
msg: unable to connect to cs01.hq.adap.tv: ConnectAuthError(cs01.hq.adap.tv)
failed: [as01.hq.adap.tv] => {"failed": true}
msg: unable to connect to as01.hq.adap.tv: ConnectAuthError(as01.hq.adap.tv)
failed: [fw01.hq.adap.tv] => {"failed": true}
msg: unable to connect to fw01.hq.adap.tv: ConnectTimeoutError(fw01.hq.adap.tv)

FATAL: all hosts have already failed -- aborting

This is with the following hosts configuration:

[network_hq]
cs01.hq.adap.tv ansible_ssh_private_key_file=/home/ops/.ssh/rtr_rsa
as01.hq.adap.tv ansible_ssh_private_key_file=/home/ops/.ssh/rtr_rsa
fw01.hq.adap.tv ansible_ssh_private_key_file=/home/ops/.ssh/rtr_rsa

I have verified that I can ssh when using that key. The relevant configuration for the playbook:

  tasks:
    - name: Deploying Configuration
      junos_install_config:
        host={{ inventory_hostname }}
        user=ansible
        file=/tmp/{{ inventory_hostname }}.set
        logfile=/etc/ansible/logs/{{ inventory_hostname }}.log
        timeout="300"

And the log (which isn't helpful):

$ cat logs/cs01.hq.adap.tv.log
2014-06-13 09:24:57,657:CONFIG:cs01.hq.adap.tv:connecting to host: [email protected]
2014-06-13 09:39:48,110:CONFIG:cs01.hq.adap.tv:connecting to host: [email protected]
2014-06-13 10:05:38,849:CONFIG:cs01.hq.adap.tv:connecting to host: [email protected]
2014-06-13 10:09:00,972:CONFIG:cs01.hq.adap.tv:connecting to host: [email protected]

junos_get_facts: On a dual RE, junos_get_facts module fails after a RE switchover

Module: junos_get_facts
Host Model: mx480.

Steps to reproduce:

  1. On a dual RE router, run an ansible playbook which consists of below code.
  2. Verify that the playbook results for Get Junos Facts is fine.
  3. Now issue an RE switchover and wait for the device to restore master/backup RE.
  4. Run the playbook again after the switchover. Shows below error.

Playbook:

  • name: Junos OS version
    hosts: all
    connection: local
    gather_facts: no

    tasks:

    • include: task_check_nc
    • name: Get Junos Facts
      junos_get_facts:
      host={{ inventory_hostname }}
      register: junos

Playbook result when re0 is the master and re1 is backup:

regress@vm-nomadic-ubuntu:~/ansible_junos/mydir_ansible$ ansible-playbook pb/facts --limit andrina -v

PLAY [Junos OS version] *******************************************************

TASK: [checking NETCONF] ******************************************************
ok: [andrina] => {"changed": false, "elapsed": 0, "item": "", "path": null, "port": 830, "search_regex": null, "state": "started"}

TASK: [Get Junos Facts] *******************************************************
ok: [andrina] => {"changed": false, "facts": {"2RE": true, "HOME": "/var/home/regress", "RE0": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "master", "model": "RE-S-1800x4", "status": "OK", "up_time": "7 days, 23 minutes, 36 seconds"}, "RE1": {"last_reboot_reason": "Router rebooted after a normal shutdown.", "mastership_state": "backup", "model": "RE-S-1800x4", "status": "OK", "up_time": "7 days, 23 minutes, 50 seconds"}, "domain": "englab.juniper.net", "fqdn": "andrina.englab.juniper.net", "hostname": "andrina", "ifd_style": "CLASSIC", "master": "RE0", "model": "MX480", "personality": "MX", "serialnumber": "JN10FE440AFB", "switch_style": "BRIDGE_DOMAIN", "version": "12.1-20140402.0", "version_RE0": "12.1-20140402.0", "version_RE1": "12.1-20140402.0"}}

PLAY RECAP ********************************************************************
andrina : ok=2 changed=0 unreachable=0 failed=0


Playbook result when master is re1 and backup is re0:

regress@vm-nomadic-ubuntu:~/ansible_junos/mydir_ansible$ ansible-playbook pb/facts --limit andrina -v

PLAY [Junos OS version] *******************************************************

TASK: [checking NETCONF] ******************************************************
ok: [andrina] => {"changed": false, "elapsed": 0, "item": "", "path": null, "port": 830, "search_regex": null, "state": "started"}

TASK: [Get Junos Facts] *******************************************************
failed: [andrina] => {"failed": true, "parsed": false}
invalid output was: Traceback (most recent call last):
File "/home/regress/.ansible/tmp/ansible-tmp-1397213264.56-247484810680075/junos_get_facts", line 1305, in
main()
File "/home/regress/.ansible/tmp/ansible-tmp-1397213264.56-247484810680075/junos_get_facts", line 95, in main
dev.open()
File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 247, in open
self.facts_refresh()
File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 412, in facts_refresh
gather(self, self._facts)
File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/facts/chassis.py", line 28, in chassis
facts['model'] = x_ch.find('description').text
AttributeError: 'NoneType' object has no attribute 'find' >>>>ERROR

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/regress/facts.retry

andrina : ok=1 changed=0 unreachable=0 failed=1


Expected Result

Junos get facts should return the device information after the switchover without errors.

Return unreachable instead of failed when unreachable

Currently, when ansible-junos-stdlib tails to connect to a target host, ansible sees it as "failed" while it should reports it as "unreachable". especially as ansible-playbook has different return code for failed vs unreachable.

For example:
msg: unable to connect to xxx: ConnectTimeoutError(xxx)
[...]
xxx : ok=1 changed=0 unreachable=0 failed=1

Thanks

Extend junos_get_facts savedir to save facts when using netconf

At current the savedir variable is only used for netconify. Extend this to support both modes.

Temporary work around:

---
  - name: Get Device Facts
    hosts: all
    connection: local
    gather_facts: no

    tasks:
     - name: Checking NETCONF connectivity
       wait_for: host={{ inventory_hostname }} port=22 timeout=5

     - name: Retrieve information from devices running Junos OS
       junos_get_facts:
        host={{ inventory_hostname }}
        user=user
        passwd=passwd
       register: junos

     - name: version
       debug: msg="{{ junos.facts }}"

     - copy: content="{{ junos }}" dest=./{{ inventory_hostname }}.json

add junos_rollback

add the ability to rollback to a specific configuration, identified by number [1-50].

junos_rollback:
  host={{ inventory_hostname }}
  rollback=1

unable to download Juniper.junos role

Hello,

I am trying to download the Juniper.junos role and I am getting below error.

root@ubuntu:~# ansible-galaxy install Juniper.junos

  • downloading role 'junos', owned by Juniper
    [WARNING]: - Juniper.junos was NOT installed successfully: ERROR! - sorry, Juniper.junos was not found on https://galaxy.ansible.com.

ERROR! - you can use --ignore-errors to skip failed roles and finish processing the list.

Playbook fails on existing configuration

I believe I am running into a bug with either the Ansible module and/or the junos-eznc module. I have a simple playbook to install a configuration on a device (have tried this on multiple devices, all fail, this is on a EX2200-C, 12.3R6.6, with Ansible vs 1.9.1, Ansible Module v1.1.0, junos-eznc 1.2.0).

The test scenario is to update the VLAN configuration on one or more ports, the existing configuration has ge-0/0/7 with VL0001 configured and I want to change it to VL0002, this fails as there appears to be no way to update the configuration (the only option I have seen is the overwrite option which blasts the entire configuration).

Existing Configuration (snippet)
show interfaces ge-0/0/7    
description TEST;
unit 0 {
    family ethernet-switching {
        port-mode access;
        vlan {
            members VL0001-192.168.1.0_24;
        }
    }
}
YAML File:

---
- name: Load Junos Config
  hosts: juniper
  roles:
    - Juniper.junos
  connection: local
  gather_facts: no
  tasks:
    - name: Verifying NETCONF
      wait_for: host={{ ansible_ssh_host }} port=830

    - name: Set System Login Message
      junos_install_config:
        host={{ ansible_ssh_host }}
        file=load_config.conf
        overwrite=false
        user={{ juniper_user }}
        logfile="/tmp/junos_ansible.log
Configuration File:
interfaces {
    ge-0/0/7 {
        description TEST;
        unit 0 {
            family ethernet-switching {
                port-mode access;
                vlan {
                    members VL0002;
                }
            }
        }
    }
}
Ansible Run and Error:
ansible-playbook -i /etc/ansible/hosts /etc/ansible/playbooks/load_config.yml 

PLAY [Load Junos Config] ****************************************************** 

TASK: [Verifying NETCONF] ***************************************************** 
ok: [sw01.lab]

TASK: [Update VLAN] ********************************************** 
failed: [sw01.lab] => {"changed": false, "failed": true, "file": "/etc/ansible/playbooks/load_config.conf"}
msg: Unable to commit configuration:error,None,Access interface <ge-0/0/7.0> has more than one vlan member: <VL0002> and <VL0001>

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/ansible/load_config.retry

sw01.lab         : ok=1    changed=0    unreachable=0    failed=1

Is there a way to update the configuration (or delete the specific stanza prior to the update) for stanza's that can take only a single value or is this just a limitation of the module? Full disclosure, I have run into this same problem with the junos-eznc module while testing out Python scripts and have found no resolution to this issue either (for that module it was recommended to use the "delete: vlan" command just before the stanza, but that did not work), given that the Junos Ansible module uses junos-eznc I am guessing I am running into the same issue.

better login error message handling

As of junos-pyez version 0.1.2 there are new Exceptions for the various login/auth failures. Need to expose this information into the ansible modules failure message.

<junos_get_facts_console> NEGATIVE TESTING.Irrelevant error when TERMSERV settings are incorrect

Model; Any
Module: junos_get_facts_console.

Steps to reproduce:
The terminal server is incorrect in the playbook.
for Albert correct terminal server is bngsquid11 and on port 7026

YAML CODE HAS

        console="--telnet=bngsquid49-7044.englab.juniper.net,7044"

Script returns:

failed: [albert] => {"failed": true, "parsed": false}
invalid output was: ERROR: bad_passwd


FATAL: all hosts have already failed -- aborting

Since the router is in amnesiac mode, there is no relevance to password. Should return something relevant like no reply from termserver or port.

junos_install_os not supported with EX4300 Virtual Chassis.

When I use the junos_install_os with a stack of EX4300 in a VC, only the Master RE reboots at the end and the playbook fails. I have to manually reboot the other members in the virtual chassis to finalize the installation.

Thanks,
Patrick

AttributeError' object has no attribute 'xml' while doing commit_check (junos_install_config module)

We are using 'junos_install_config' module to load a new configuration on a pre-configured juniper MX device

Device configuration:

interfaces {
lt-0/0/10 {
unit 0 {
encapsulation ethernet;
peer-unit 1;
family inet {
address 10.1.1.4/31;
}
}
unit 1 {
encapsulation ethernet;
peer-unit 0;
family inet {
address 10.1.1.5/31;
}
}
}
}
After doing commit check of following configuration on the juniper MX device through CLI, device reported below mentioned error:
interfaces {
lt-0/0/10 {
unit 1 {
peer-unit 1;

    }

}
}

Error:
[edit interfaces]
'lt-0/0/10'
unit 0: peer-unit 1 refers to other unit
error: configuration check-out failed

While doing commit check of the same configuration through ansible-playbook using module 'junos_install_config' and got following exception :

failed: [**.__..*] => {"failed": true, "parsed": false}
invalid output was: Traceback (most recent call last):
File "/tmp/.ansible/tmp/ansible-tmp-1442855394.02-81768901013637/junos_install_config", line 1516, in
main()
File "/tmp/.ansible/tmp/ansible-tmp-1442855394.02-81768901013637/junos_install_config", line 420, in main
_ldr(module)
File "/tmp/.ansible/tmp/ansible-tmp-1442855394.02-81768901013637/junos_install_config", line 288, in _load_via_netconf
cu.commit_check()
File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/config.py", line 169, in commit_check
return JXML.rpc_error(err.xml)
AttributeError: 'exceptions.AttributeError' object has no attribute 'xml'

We feel that instead of exception we should have received proper error, can we fix this?

Environment:
Python 2.7.6
ansible-playbook 1.5.4
junos-eznc 1.2.2
Ubuntu

security nat source acting all weird

Hi all,

I am new to Juniper OS ( 12.1X44.3 ) and I have tried to setup security nat source with the following:

set security address-book global address dmz70 wildcard-address 192.168.7.0/255.255.255.0
set security address-book global address lan50 wildcard-address 192.168.5.0/255.255.255.0
set security address-book global address lan60 wildcard-address 192.168.6.0/255.255.255.0
set security address-book global address lan80 wildcard-address 192.168.8.0/255.255.255.0
set security address-book global address la2vpn wildcard-address 172.16.8.0/255.255.255.0
set security address-book global address sj2vpn wildcard-address 172.16.11.0/255.255.255.0
set security address-book global address sj wildcard-address 172.16.1.0/255.255.255.0
set security address-book global address va2-4 wildcard-address 10.0.4.0/255.255.255.0
set security address-book global address va2-8 wildcard-address 10.0.8.0/255.255.255.0

set security nat source rule-set snat-out from zone dmz
set security nat source rule-set snat-out from zone trust
set security nat source rule-set snat-out to zone untrust

set security nat source rule-set snat-out rule VPNNATOFF match source-address lan50
set security nat source rule-set snat-out rule VPNNATOFF match source-address lan60
set security nat source rule-set snat-out rule VPNNATOFF match source-address lan80
set security nat source rule-set snat-out rule VPNNATOFF match source-address la2vpn
set security nat source rule-set snat-out rule VPNNATOFF match source-address sj2vpn
set security nat source rule-set snat-out rule VPNNATOFF match source-address sj
set security nat source rule-set snat-out rule VPNNATOFF match source-address dmz70
set security nat source rule-set snat-out rule VPNNATOFF match destination-address va2-4
set security nat source rule-set snat-out rule VPNNATOFF match destination-address va2-8
set security nat source rule-set snat-out rule VPNNATOFF then source-nat off

set security nat source rule-set snat-out rule snat-out match source-address lan50
set security nat source rule-set snat-out rule snat-out match source-address lan60
set security nat source rule-set snat-out rule snat-out match source-address lan80
set security nat source rule-set snat-out rule snat-out match source-address dmz70
set security nat source rule-set snat-out rule snat-out then source-nat interface


Ansible playbook ran until completion without any errors but then I got this from the above. This is really unexpected and I just do not know where x.x.114.94/32 is from. I do not have anything in my config with this x.x.114.94/32 (x.x were replaced for security).

steven@sc2-jnpr-fw# show security nat source
rule-set snat-out {
from zone [ dmz trust ];
to zone untrust;csteven@sc2-jnpr-fw# show security nat source
rule-set snat-out {
from zone [ dmz trust ];
to zone untrust;
rule VPNNATOFF {
match {
source-address x.x.114.94/32;
destination-address x.x.114.94/32;
}
then {
source-nat {
off;
}
}
}
rule snat-out {
match {
source-address x.x.114.94/32;
}
then {
source-nat {
interface;
}
}
}
}

I grepped my config and nothing of x.x114.94/32 is in there except for the nat source entries.

steven@sc2-jnpr-fw# show |grep 114.94
source-address x.x.114.94/32;
destination-address x.x.114.94/32;
source-address x.x.114.94/32;

Thanks.

ConnectAuthError when using passphrased ssh key

I am trying to get the library to work with ssh-key authentication. If the key is not protected by a password everything is fine. As soon as I protect it with a password I get the ConnectAuthError.

Other playbooks using the OpenSSH implementation connecting to Linux servers work just fine with the password protected key. I just get prompted by the system once for the password and they run.

Best regards,
Jesse

<junoz_zeroize> Need logging for junos_zeroize.

Model : Any
Module: junos_zeroize

While testing junos_zeroize, found that there is no support for logging provided. It only returns changed “true” or “false”.
It gives a better understanding of what is happening on the device if the device logs can be captured and logged.

reference :
Juniper/py-junos-eznc#233

install_config throws errors

We have tried on both an EX4200 and SRX240 and get this error using this playbook. We thought it may be a PyEZ version but we have tried 1.2.2 and 1.2.3

TASK: [Install Junos OS package] **********************************************
failed: [10.210.14.170] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/home/htpcguides/.ansible/tmp/ansible-tmp-1440670135.82-236773385389926/junos_install_os", line 1874, in <module>
    main()
  File "/home/htpcguides/.ansible/tmp/ansible-tmp-1440670135.82-236773385389926/junos_install_os", line 256, in main
    results = junos_install_os(module, dev)
  File "/home/htpcguides/.ansible/tmp/ansible-tmp-1440670135.82-236773385389926/junos_install_os", line 199, in junos_install_os
    ok = sw.install(package, **sw_args)
  File "/home/htpcguides/.local/lib/python2.7/site-packages/jnpr/junos/utils/sw.py", line 386, in install
    checksum=checksum)
  File "/home/htpcguides/.local/lib/python2.7/site-packages/jnpr/junos/utils/sw.py", line 267, in safe_copy
    self.put(package, remote_path, progress)
  File "/home/htpcguides/.local/lib/python2.7/site-packages/jnpr/junos/utils/sw.py", line 131, in put
    scp.put(package, remote_path)
  File "/home/htpcguides/.local/lib/python2.7/site-packages/scp.py", line 154, in put
    self._send_files(files)
  File "/home/htpcguides/.local/lib/python2.7/site-packages/scp.py", line 245, in _send_files
    self._progress(basename, size, 0)
TypeError: update_my_progress() takes exactly 2 arguments (3 given)

Has POE in get_facts

Same as the has_2RE, it would be useful if get_facts could returns the POE capability of the device as well. (None, POE, POE+)

Thanks

junos_install_config causes Ansible to incorrectly report failure when warnings exist

Ansible output (redacted):

TASK: [Deploy configuration] **************************************************
failed: [router.example.net] => {"changed": false, "failed": true, "file": "/mypath/config.xml"}
msg: Unable to make changes

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/Users/myuser/deploy.retry

router.example.net : ok=4    changed=0    unreachable=0    failed=1

Netconf log file in router.example.net shows:

Mar 10 14:43:06 [37567] Outgoing: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/13.2X51/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:c5c2a4ee-c733-11e4-8b93-3c15c2d90eda">
Mar 10 14:43:06 [37567] Outgoing: <commit-results>
Mar 10 14:43:12 [37567] Outgoing: <rpc-error>
Mar 10 14:43:12 [37567] Outgoing: <error-type>application</error-type>
Mar 10 14:43:12 [37567] Outgoing: <error-tag>invalid-value</error-tag>
Mar 10 14:43:12 [37567] Outgoing: <error-severity>warning</error-severity>
Mar 10 14:43:12 [37567] Outgoing: <error-path>[edit routing-instances BACKNET protocols]</error-path>
Mar 10 14:43:12 [37567] Outgoing: <error-message>mgd: requires 'bgp' license</error-message>
Mar 10 14:43:12 [37567] Outgoing: <error-info>
Mar 10 14:43:12 [37567] Outgoing: <bad-element>bgp</bad-element>
Mar 10 14:43:12 [37567] Outgoing: </error-info>
Mar 10 14:43:12 [37567] Outgoing: </rpc-error>
Mar 10 14:43:49 [37567] Outgoing: <routing-engine junos:style="normal">
Mar 10 14:43:49 [37567] Outgoing: <name>fpc0</name>
Mar 10 14:43:49 [37567] Outgoing: <commit-check-success/>
Mar 10 14:44:14 [37567] Outgoing: <commit-success/>
Mar 10 14:44:16 [37567] Outgoing: </routing-engine>
Mar 10 14:44:16 [37567] Outgoing: </commit-results>
Mar 10 14:44:16 [37567] Outgoing: <ok/>
Mar 10 14:44:16 [37567] Outgoing: </rpc-reply>
Mar 10 14:44:16 [37567] Outgoing: ]]>]]>
Mar 10 14:44:16 [37567] Incoming: <?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:e98608d7-c733-11e4-bc64-3c15c2d90eda"><nc:close-session/></nc:rpc>]]>]]>
Mar 10 14:44:16 [37567] Outgoing: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/13.2X51/junos" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:e98608d7-c733-11e4-bc64-3c15c2d90eda">
Mar 10 14:44:16 [37567] Outgoing: <ok/>
Mar 10 14:44:16 [37567] Outgoing: </rpc-reply>

We are working on the license thing, but the configuration is actually committed, so Ansible incorrectly reports that changes could not be made.

Shebang in python tasks

Please change the shebang from "/usr/bin/python" to "/usr/bin/env python" for all task scripts.

<junoz_zeroize> Need logging for junos_zeroize.

Model : Any
Module: junos_zeroize

While testing junos_zeroize, found that there is no support for logging provided. It only returns changed “true” or “false”.
It gives a better understanding of what is happening on the device if the device logs can be captured and logged.

[ansible-junos-stdlib] Need support for no-validate flag.

Model: All supported Models
Ansible module: junos_install_os
Use case: Juniper router allows user to override existing configuration and install image using "no-validate" flag.

Current code:

def main():
module = AnsibleModule(
argument_spec = dict(
host=dict(required=True),
package=dict(required=True),
user=dict(required=False, default=os.getenv('USER')),
passwd=dict(required=False, default=None),
version=dict(required=False, default=None),
logfile=dict(required=False, default=None),
no_copy=dict(required=False, choices=BOOLEANS, default=False),
reboot=dict(required=False, choices=BOOLEANS, default=True),
reboot_pause=dict(required=False, type='int', default=10)
),
supports_check_mode = True
)

Already there is no-copy option available. Support for no-validate flag is needed.

junos_install_os:Better Handling of error message needed when junos install fails.

Host: m120
Image location: /usr/local/junos/images/
Current Version on the host: 12.1R8
Playbook code:
- name: install Junos OS package
junos_install_os:
host={{ inventory_hostname }}
version=13.2R4.6
package=/usr/local/junos/images/jinstall-13.2R4.6-domestic-signed.tgz
logfile=/usr/local/junos/log/loadimage.log
register: sw

Issue:
Since the version on router is not equal to the install image version(13.2R4.6), Image install should go through, however, error appears:

regress@vm-nomadic-ubuntu:~/ansible_junos/mydir_ansible/pb/EXVC$ ansible-playbook software --limit richie -vvvv

PLAY [Junos OS] ***************************************************************

TASK: [checking NETCONF] ******************************************************
REMOTE_MODULE wait_for host=richie port=830 timeout=5
EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006 && echo $HOME/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006']
PUT /tmp/tmpc6zLw4 TO /home/regress/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006/wait_for
EXEC ['/bin/sh', '-c', '/usr/bin/python /home/regress/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006/wait_for; rm -rf /home/regress/.ansible/tmp/ansible-tmp-1398683803.04-100297249877006/ >/dev/null 2>&1']
ok: [richie] => {"changed": false, "elapsed": 1, "item": "", "path": null, "port": 830, "search_regex": null, "state": "started"}

TASK: [install Junos OS package] **********************************************
REMOTE_MODULE junos_install_os host=richie version=11.4R10.1 package=/var/tmp/jinstall-11.4R10.1-domestic-signed.tgz logfile=/usr/local/junos/log/loadimage.log
EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834 && echo $HOME/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834']
PUT /tmp/tmpAcHgHu TO /home/regress/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834/junos_install_os
EXEC ['/bin/sh', '-c', '/usr/bin/env python2.7 /home/regress/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834/junos_install_os; rm -rf /home/regress/.ansible/tmp/ansible-tmp-1398683804.88-234934252741834/ >/dev/null 2>&1']
failed: [richie] => {"changed": true, "check_mode": false, "failed": true, "ver": {"has": "12.1R8", "should": "11.4R10.1"}}
msg: Unable to install the software

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/regress/software.retry

richie : ok=1 changed=0 unreachable=0 failed=1

Expected Result:
Image install should go through.
If there is an issue: Appropriate error message should appear.
Current message does not provide any information to the user.

<junos_install_config> on an m120/mx480 dual RE, load set commands fail.

Model : m120 (Richie)
configuration saved in .set file extension :

File contents:
set policy-options policy-statement P0 term term1 from route-type external
set policy-options policy-statement P0 term term1 then preference 0
set policy-options policy-statement P0 term term1 then accept
set policy-options policy-statement P1 term term1 from route-type external

task:

  • name: Configure using ansible
    junos_install_config:
    host={{ inventory_hostname }}
    file=/usr/local/junos/config/only_policy.set
    timeout=30
    logfile={{logdir}}/config.log

Problem:
Seems like .set is considered as a .conf and is throwing syntax error.
ONLY FOR M120. Tried on M10i DualRE/ EX VC / SRX cluster, works fine.

Output:
TASK: [Configure using ansible] ***********************************************
failed: [richie] => {"changed": false, "failed": true, "file": "/usr/local/junos/config/only_policy.set"}
msg: Unable to make changes

FATAL: all hosts have already failed -- aborting

Log File:
2014-05-26 16:33:17,354:CONFIG:richie:connecting to host: regress@richie
2014-05-26 16:33:21,905:CONFIG:richie:pushing file: /usr/local/junos/config/only_policy.set
2014-05-26 16:33:21,905:CONFIG:richie:taking lock
2014-05-26 16:33:22,020:CONFIG:richie:loading config
2014-05-26 16:33:22,451:CONFIG:richie:Unable to make changes

Worked fine on Popeye, albert, triplane.

junos_get_config not working with Junos 10.4

I'm trying to retrieve router configurations with the task:

  • name: retrieve router configuration
    junos_get_config:
    host: "{{ inventory_hostname }}"
    passwd: ""
    logfile: get_config.log
    dest: "{{ inventory_hostname }}.txt"
    format: text

this works fine with my SRX routers, but i got a blank file with my J2320 10.4R10.7 routers. Nothing wrong in the log:

2015-10-02 12:52:56,542:CONFIG::connecting to host: user@host:830
2015-10-02 12:52:56,642:ncclient.transport.ssh:Connected (version 2.0, client OpenSSH_4.4)
2015-10-02 12:52:57,145:ncclient.transport.ssh:Authentication (password) successful!
2015-10-02 12:52:57,913:ncclient.transport.session:initialized: session-id=70914 | server_capabilities=['http://xml.juniper.net/dmi/system/1.0', 'urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0', 'http://xml.juniper.net/netconf/junos/1.0', 'urn:ietf:params:xml:ns:netconf:capability:validate:1.0', 'urn:ietf:params:xml:ns:netconf:capability:candidate:1.0', 'urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file', 'urn:ietf:params:xml:ns:netconf:base:1.0']
2015-10-02 12:52:57,913:CONFIG::Getting config with options={'format': 'text'}
2015-10-02 12:52:57,920:ncclient.operations.rpc:Requesting 'ExecuteRpc'
2015-10-02 12:52:58,048:ncclient.operations.rpc:Requesting 'CloseSession'

If i change the format to xml i got the following error:

2015-10-02 12:56:01,810:CONFIG::Getting config with options={'format': 'xml'}
2015-10-02 12:56:01,816:ncclient.operations.rpc:Requesting 'ExecuteRpc'
2015-10-02 12:56:01,890:CONFIG::Uncaught exception - please report: Type 'bool' cannot be serialized.

The example that comes with ncclient works ok with xml:

from ncclient import manager

with manager.connect(host="", port=830, username="", password="<password", hostkey_verify=False, device_params={'name':'junos'}) as m:
c = m.get_config(source='running').data_xml
with open("%s.xml" % "", 'w') as f:
f.write(c)

any ideas?

TransportError: Not connected to NETCONF server

I've recently started getting errors trying to push configs to a couple of ex4200-48t series switches running 12.3R4.6

Ansible shows:

TASK: [Deploy configuration] **************************************************
failed: [device1.domain.net] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/Users/cvicente/.ansible/tmp/ansible-tmp-1439845015.33-50192573969685/junos_install_config", line 2001, in <module>
    main()
  File "/Users/cvicente/.ansible/tmp/ansible-tmp-1439845015.33-50192573969685/junos_install_config", line 399, in main
    _ldr(module)
  File "/Users/cvicente/.ansible/tmp/ansible-tmp-1439845015.33-50192573969685/junos_install_config", line 303, in _load_via_netconf
    dev.close()
  File "/Library/Python/2.7/site-packages/jnpr/junos/device.py", line 502, in close
    self._conn.close_session()
  File "/Library/Python/2.7/site-packages/ncclient/manager.py", line 156, in wrapper
    return self.execute(op_cls, *args, **kwds)
  File "/Library/Python/2.7/site-packages/ncclient/manager.py", line 226, in execute
    raise_mode=self._raise_mode).request(*args, **kwds)
  File "/Library/Python/2.7/site-packages/ncclient/operations/session.py", line 28, in request
    return self._request(new_ele("close-session"))
  File "/Library/Python/2.7/site-packages/ncclient/operations/rpc.py", line 291, in _request
    self._session.send(req)
  File "/Library/Python/2.7/site-packages/ncclient/transport/session.py", line 147, in send
    raise TransportError('Not connected to NETCONF server')
ncclient.transport.errors.TransportError: Not connected to NETCONF server


FATAL: all hosts have already failed -- aborting

The only error I see in the netconf logs on the device is:

Aug 17 20:45:25 [11848] Incoming: <?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:e32a4f4c-4520-11e5-9c26-3c15c2d90eda"><get-configuration compare="rollback" rollback="0" format="text"/></nc:rpc>]]>]]>
Aug 17 20:45:25 [11848] Outgoing: <!-- netconf error: syntax error, expecting &lt;rpc&gt; -->
Aug 17 20:45:26 [11848] Outgoing: <ok/>
Aug 17 20:45:26 [11848] Outgoing: <!-- session end at 2015-08-17 20:45:26 UTC -->

I'm not sure if it's related or not.

I'm a bit confused because we've been pushing configs to these switches for a long time now.

I'm running junos-py-ez 1.2.2 and ansible-junos-stdlib 1.1.0

I'd be very grateful for any clues.

enhance junos_install_config to load from Junos filesys

Add the ability to load configuration stored locally on the Junos filesystem. Perhaps something like:

junos_install_config:
  host={{ inventory_hostname }}
  file=my_backup.conf
  on_host=yes

assumes that the file "my_backup.conf" is located in the $HOME directory on the Junos device.

Banner text shows up in diffs randomly

This may not be a bug in this module, but I'd like to ask here in case someone has any clues. The issue is that, when deploying changes, we randomly see these lines in the diffs:

[edit system login]
-   message "\n\n          UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED.\n   Explicit permission is required to access or configure this device.\n\n        Unauthorized attempts and actions to access or use this\n         system may result in civil and/or criminal penalties.\n\n  All action taken on or against this device is logged and monitored.\n\n\n    ";
+   message "\n\n          UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED.\n   Explicit permission is required to access or configure this device.\n\n        Unauthorized attempts and actions to access or use this\n         system may result in civil and/or criminal penalties.\n\n  All action taken on or against this device is logged and monitored.\n\n\n    ";

The template that covers this section looks like this (we use XML format):

  <login>
    <message>


          UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED.
   Explicit permission is required to access or configure this device.

        Unauthorized attempts and actions to access or use this
         system may result in civil and/or criminal penalties.

  All action taken on or against this device is logged and monitored.


    </message>

I say "randomly" because we see the diffs coming from some devices, sometimes.

It is particularly problematic when we do periodic "dry-runs" to detect variations from the canonical configurations.

Thanks in advance for any pointers.

junos_install_os: Log needs to be printed when version is same as installed.

Host: Asthra
Model: srx5500
Running version on the router: 11.4R7
Installing version : 11.4R7

Playbook code:

  • name: Junos OS
    hosts: all
    connection: local
    gather_facts: no
    vars:
    restart_wait_time: 3600
    reboot: 'yes'
    tasks:
    • name: install Junos OS package
      junos_install_os:
      host={{ inventory_hostname }}
      version=11.4R7
      package=/usr/local/junos/images/junos-srx5000-11.4R7-domestic.tgz
      logfile=/usr/local/junos/log/software.log
      register: sw

The version on the router and playbook code is same. Hence should abort.

But the playbook result is not clear:

TASK: [install Junos OS package] **********************************************
ok: [asthra] => {"changed": false, "check_mode": false, "ver": {"has": "11.4R7", "should": "11.4R7"}}

User has to open the log and see the actual error:

2014-05-12 14:42:23,815:asthra:upgrade pending reboot cycle, please be patient.
2014-05-12 14:42:23,930:asthra:pausing: 10
2014-05-12 14:42:33,940:asthra:process completed OK.
2014-05-12 14:55:13,503:asthra:No need to perform upgrade: 11.4R7

Instead, the same message can be printed as a part of playbook result.

Code junos_install_os:

if need_upgrade is False:
do_log("No need to perform upgrade: {}".format( has_ver ))

An additional message to be printed as result:
results['msg'] = "No need to perform upgrade: {}"

junos_install_config fails to load config with "Unable to load config: 'list' object has no attribute 'getiterator'" error

I am getting the following error when using the junos_install_config module (v1.2.0):

TASK: [commit_config | Pushing config ... please wait] ************************
failed: [crtj-si38-0001] => {"failed": true}
msg: Unable to load config: 'list' object has no attribute 'getiterator'

The play is common across all devices but I only get the error with certain ones. For others it is working correctly. Here's the play:

  • name: Pushing config ... please wait
    ignore_errors: True
    junos_install_config:
    host={{ inventory_hostname }}
    user={{ netconf_user }}
    port={{ netconf_port }}
    passwd={{ netconf_passwd }}
    file={{ junos_conf }}
    overwrite=yes
    logfile={{ log }}
    diffs_file=/var/tmp/build/log/{{ inventory_hostname }}-diff-{{ build }}.log
    comment="Jenkins {{ build }}"
    timeout=300

I've located the offending code. It happens within the cu.load(**load_args) call within the junos_install_config module. It is not clear to me why load_args is not iterable in certain circumstances.

RpcTimeoutError while get-checksum-information

Hi,

After trying to push an upgrade on 3 similar EX2200, I got an error on only one of them:

Traceback (most recent call last):
  File "/home/xionox/.ansible/tmp/ansible-tmp-1433407957.74-148018357886798/junos_install_os", line 1867, in <module>
    main()
  File "/home/xionox/.ansible/tmp/ansible-tmp-1433407957.74-148018357886798/junos_install_os", line 255, in main
    results = junos_install_os(module, dev)
  File "/home/xionox/.ansible/tmp/ansible-tmp-1433407957.74-148018357886798/junos_install_os", line 198, in junos_install_os
    ok = sw.install(package, **sw_args)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/sw.py", line 385, in install
    checksum=checksum)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/sw.py", line 283, in safe_copy
    remote_checksum = self.remote_checksum(remote_package)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/utils/sw.py", line 225, in remote_checksum
    rsp = self.rpc.get_checksum_information(path=remote_package)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/rpcmeta.py", line 137, in _exec_rpc
    return self._junos.execute(rpc)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/decorators.py", line 25, in wrapper
    return function(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 520, in execute
    raise EzErrors.RpcTimeoutError(self, rpc_cmd_e.tag, self.timeout)
jnpr.junos.exception.RpcTimeoutError: RpcTimeoutError(<myswitch>,get-checksum-information,30)

Calculating the md5 on the device works fine (and match the original file):
myswitch> file checksum md5 /var/tmp/junos-ex2200-12.3R9-S1.tgz
MD5 (/var/tmp/junos-ex2200-12.3R9-S1.tgz) = dab7e8ff0cfabcd55c29b94cbf716bbd
the 3 switches are running 11.4.

Please let me know if I can help.

Thanks

junos_install_config incorrectly reporting syntax error

junos_install_config fails reporting a syntax error for a config that applies without error, nor warning, when committed manually.

Here's a log showing ansible failure and that the config can be applied correctly.

dgethings@ubuntu-server1 ~/git/jnpr_ps_16596_ansible
% ansible-playbook -i mx-hosts pe-tasks.yml

PLAY [Creating build directories for each host] *******************************

TASK: [set_fact ] *************************************************************
ok: [crtj-dc1-0401]
ok: [crtj-dc1-0001]
ok: [crtj-dc1-0002]

TASK: [create host build temp directory] **************************************
ok: [crtj-dc1-0401]
ok: [crtj-dc1-0001]
ok: [crtj-dc1-0002]

PLAY [Template-build DCI-PE] **************************************************

TASK: [pe | Apply PE configuration] *******************************************
failed: [crtj-dc1-0401] => {"changed": false, "failed": true, "file": "/home/dgethings/git/jnpr_ps_16596_ansible/build/crtj-dc1-0401/crtj-dc1-0401.conf", "item": ""}
msg: Unable to make changes
changed: [crtj-dc1-0001]
changed: [crtj-dc1-0002]

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/dgethings/pe-tasks.retry

crtj-dc1-0001 : ok=3 changed=1 unreachable=0 failed=0
crtj-dc1-0002 : ok=3 changed=1 unreachable=0 failed=0
crtj-dc1-0401 : ok=2 changed=0 unreachable=0 failed=1

dgethings@ubuntu-server1 ~/git/jnpr_ps_16596_ansible
% grep crtj-dc1-0401 dg.log
2014-05-12 02:04:25,786:CONFIG:crtj-dc1-0401:connecting to host: jnpr@crtj-dc1-0401
2014-05-12 02:04:31,360:CONFIG:crtj-dc1-0401:pushing file: /home/dgethings/git/jnpr_ps_16596_ansible/build/crtj-dc1-0401/crtj-dc1-0401.conf
2014-05-12 02:04:31,360:CONFIG:crtj-dc1-0401:taking lock
2014-05-12 02:04:31,476:CONFIG:crtj-dc1-0401:loading config
2014-05-12 02:04:31,795:CONFIG:crtj-dc1-0401:unable to load config:syntax error
2014-05-12 02:04:31,795:CONFIG:crtj-dc1-0401:Unable to make changes
dgethings@ubuntu-server1 ~/git/jnpr_ps_16596_ansible
% scp /home/dgethings/git/jnpr_ps_16596_ansible/build/crtj-dc1-0401/crtj-dc1-0401.conf jnpr@crtj-dc1-0401:/var/tmp/
Password:
crtj-dc1-0401.conf 100% 13KB 12.7KB/s 00:00
dgethings@ubuntu-server1 ~/git/jnpr_ps_16596_ansible
% ssh jnpr@crtj-dc1-0401
Password:
--- JUNOS 13.3R1.6 built 2014-01-17 02:57:36 UTC
jnpr@crtj-dc1-0401-RE0> configure
Entering configuration mode
Users currently editing the configuration:
root terminal u0 (pid 2605) on since 2014-04-11 11:41:35 PDT, idle 4w2d 14:57
[edit]

[edit]
jnpr@crtj-dc1-0401-RE0# load override /var/tmp/crtj-dc1-0401.conf
load complete

[edit]
jnpr@crtj-dc1-0401-RE0# commit and-quit
commit complete
Exiting configuration mode

jnpr@crtj-dc1-0401-RE0> quit

file with extention *.set is not converted to xml and raises error on the shell

Here what i am trying to implement, simple playbook
tasks:
- name: installing initial config to Amnesiac
junos_install_config:
host={{ inventory_hostname }}
user=root
console="--telnet={{TERMSERV}},{{TERMSERVPORT}}"
file=configs/initial.set
overwrite=yes
savedir=junos/inventory
logfile=junos/logs/initial.log

config is also very basic
set system root-authentication encrypted-password $1$usi5OLHO$2//owSkqcLsuwRb9hSeTI.
set interfaces ge-0/0/0 unit 0 family inet address 192.168.159.7/24
set system host-name router
set system time-zone GMT-3
set system services netconf ssh
set routing-options static route 0.0.0.0/0 next-hop 192.168.159.254
delete security
delete system services web-management

starting this playbook lead to ansible execution and at the task processing it just hangs
PLAY [servers] ****************************************************************

TASK: [installing initial config to Amnesiac] *********************************
^CERROR: interrupted

wireshark shows me smth interesting

...............
.........

XXXhostnameXXX (ttyd0)

login: root
root

--- JUNOS 12.1X46-D20.5 built 2014-05-14 20:38:10 UTC

.[3g.[24;9H.H.[24;17H.H.[24;25H.H.[24;33H.H.[24;41H.H.[24;49H.H.[24;57H.H.[24;65H.H.[24;73H.H

root@XXXhostnameXXX% xml-mode netconf need-trailer
xml-mode netconf need-trailer

urn:ietf:params:xml:ns:netconf:base:1.0 urn:ietf:params:xml:ns:netconf:capability:candidate:1.0 urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0 urn:ietf:params:xml:ns:netconf:capability:validate:1.0 urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file http://xml.juniper.net/netconf/junos/1.0 http://xml.juniper.net/dmi/system/1.0 1323 ]]>]]> set system root-authentication encrypted-password $1$usi5OLHO$2//owSkqcLsuwRb9hSeTI. set interfaces ge-0/0/0 unit 0 family inet address 192.168.159.7/24 set system host-name router set system time-zone GMT-3 set system services netconf ssh set routing-options static route 0.0.0.0/0 next-hop 192.168.159.254 delete security delete system services web-management

when i tried manually do what script is supposed to i got an error
XXXhostnameXXX (ttyd0)

login: root

--- JUNOS 12.1X46-D20.5 built 2014-05-14 20:38:10 UTC
root@XXXhostnameXXX% xml-mode netconf need-trailer

urn:ietf:params:xml:ns:netconf:base:1.0 urn:ietf:params:xml:ns:netconf:capability:candidate:1.0 urn:ietf:params:xml:ns:netconf:capability:confirmed-commit:1.0 urn:ietf:params:xml:ns:netconf:capability:validate:1.0 urn:ietf:params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file http://xml.juniper.net/netconf/junos/1.0 http://xml.juniper.net/dmi/system/1.0 1278 ]]>]]> error set syntax error

so it seems to me the problem is in right formatting of *.set file
i did not test with *.conf and *.xml files

Return more verbose error message

Hi,

Right now if the network device returns an error, it's properly logged in the logfile, while only "Unable to make changes" is returned to Ansible. To me, the most verbose/useful error should be returned to Ansible.
If so, I think nothing gets caught in the "except CommitError" and defaults to "except Exception".
I'll wait before trying to send a pull request :P

Thx!

junos_get_config paths broken with async

In standard mode, I can use relative paths:

  tasks:
  - name: Fetch Juniper configs
    junos_get_config:
      host="{{ inventory_hostname }}"
      dest="configs/{{ inventory_hostname }}.conf"
      format=text
      user={{ LAB_USER }}
      passwd={{ LAB_PASSWORD }}
      logfile=logs/get_configs.log
    register: config

When I invoke async:

  tasks:
  - name: Fetch Juniper configs
    junos_get_config:
      host="{{ inventory_hostname }}"
      dest="configs/{{ inventory_hostname }}.conf"
      format=text
      user={{ LAB_USER }}
      passwd={{ LAB_PASSWORD }}
      logfile=logs/get_configs.log
    async: 45
    poll: 1
    register: config

I get the error:
msg: Uncaught exception - please report: [Errno 2] No such file or directory: 'configs/<<router>>.conf' failed: [<<router>>] => {"ansible_job_id": "561876101247.26669", "changed": false, "failed": true, "finished": 1}

However, if I set full paths:

  tasks:
  - name: Fetch Juniper configs
    junos_get_config:
      host="{{ inventory_hostname }}"
      dest="/opt/ansible/configs/{{ inventory_hostname }}.conf"
      format=text
      user={{ LAB_USER }}
      passwd={{ LAB_PASSWORD }}
      logfile=/opt/ansible/logs/get_configs.log
    async: 45
    poll: 1
    register: config

everything works.

key based authentication method for junos_install_config module

We are trying to run junos_install_config module using ssh key based authentication method instead of using password

we have generated public/private rsa key on one of our instance(ubuntu) and have created a user on the MX device with authentication as ssh-rsa

But While trying to use private-key in ansible-playbook junos module (junos_install_config) , ansible-playbook throws authentication error as "ConnectAuthError"

I have attached yaml file , hosts ,conf and output file for reference

yaml file :-

name: Change description of interface
hosts: all
roles:
 - Juniper.junos
connection: local
gather_facts: no

tasks:
  - name: Change description of interface
    junos_install_config:
        host={{ inventory_hostname }}
        user={{ ansible_ssh_user }}
        port=830
        file=test.conf
        overwrite=false
        replace=false
        timeout=0
        diffs_file=commit_check_log
        logfile=commit_log  

test.conf file:-

interfaces{
ge-0/0/0 {
description "Ansible test";
}
}

host file:-
xxx.xx.xx.xxx ansible_connection=local ansible_ssh_user=testuser ansible_ssh_host=xxx.xx.xx.xxx

Command used for running playbook:-
ansible-playbook -i hosts load_config.yml --private-key="/xxxx/xxxx/xxxx/xx_key" -u testuser -vvvv

Output:-

PLAY [Get Device Facts] *******************************************************

TASK: [Change description of interface] ********************

msg: unable to connect to xxx.xx.xxx.xxx: ConnectAuthError(xxx.xx.xxx.xxx)

FATAL: all hosts have already failed -- aborting

Can you please help us in resolving this issue

TypeError: cannot concatenate 'str' and 'bool' objects

With respect to changes made under:
Juniper/py-junos-eznc#237

We need to revert the changes made in
https://github.com/Juniper/ansible-junos-stdlib/pull/9/files

Which was done considering string (Error message) returning not boolean False in case of failure.
Now we might face something like:

"Unable to install the software: " + False

Traceback (most recent call last):
File "<pyshell#0>", line 1, in
"Unable to install the software: " + False
TypeError: cannot concatenate 'str' and 'bool' objects

Hence please revert back the changes in above given file.

junos_get_facts doesn't support check_mode

When you have a playbook you run in check-only mode, modules that don't support check_mode are skipped. I noticed junos_get_facts doesn't support check_mode. Since this module does not change state on the remote device, I can't think of any reason why NOT to support check_mode. Or is there some detail I am missing?

It should be a simple fix to make this module check mode compatible and I'm happy to send a pull request.

Underlying netconify exception not handled

Exceptions raised in the underlying netconify library are not being handled by Ansible.

TASK: [Reset to baseline config] **********************************************
failed: [stag] => {"failed": true, "parsed": false}
invalid output was: ERROR: bad_passwd

Option to pass string config directly in playbook for junos_install_config

plans to add support for config changes without having external file (just by supplying a single variable) like

  • name: Update something
    junos_install_config:
    host={{ ip }}
    port={{ ncssh_port }}
    user={{ user }}
    passwd={{ password }}
    config="set system hostname NEW_NAME" <<< config string instead of a file.

Commit check var

Guys,

I'm trying to use commit check in library/junos_install_config.
Added commit_check:1 in the play-book but it didnt work.

I changed the script (junos_install_config) to make it work.
I'm not sure if its an issue or if I'm using it wrong.

Let me know. if its an issue, I'll send you the fix I did.

Thank you,
Aaron Prat

Junos_install_config throw this error "msg: failure to load configuration, aborting."

I have created ansible module call noob-ex that will push minimal configuration on the ex device and to test this module I am using EX4500 device. my device is factory reset it's just new box having no configuration. At this stage when I tried to run this ansible playbook I got error like "msg: failure to load configuration, aborting"
Can anyone help me why I am getting this error? I am using pyez version 1.2.3

Below are my playbooks

vars main/yml file

node:
console:
server: x.x.x.x
port: xxxx
oob:
noob_ip_addr: x.x.x.x

oob:
gateway: x.x.x.x
networks: x.x.x.x

netconf_user: xxxxx
netconf_passwd: lxxxxx

Tasks/main.yml

task file for ansible-role-noob-ex

  • name: Creating NOOB config
    template: src=noob.j2 dest={{ build_dir }}/noob.conf
  • name: Checking NETCONF connectivity
    wait_for: host={{ inventory_hostname }} port={{ netconf_port }} timeout=5
    register: netconf_result
    ignore_errors: True
  • name: loading minimal management configuration file
    when: netconf_result|failed
    junos_install_config:
    host={{ inventory_hostname }}
    user=root
    console="--telnet={{ node.console.server }},{{ node.console.port}}"
    file={{ build_dir }}/noob.conf
    overwrite=yes
    logfile={{ log }}

ansible Run and Error

dpatel@dharpatel-ubuntu:~/Desktop/Ansible-Modules$ ansible-playbook ex-test.yml

PLAY [all_hosts] **************************************************************

TASK: [ansible-role-noob-ex | Creating NOOB config] ***************************
ok: [10.13.106.246]

TASK: [ansible-role-noob-ex | Checking NETCONF connectivity] ******************
failed: [10.13.106.246] => {"elapsed": 6, "failed": true, "item": ""}
msg: Timeout when waiting for 10.13.106.246:830
...ignoring

TASK: [ansible-role-noob-ex | loading minimal management configuration file] ***
failed: [10.13.106.246] => {"failed": true, "item": ""}
msg: failure to load configuration, aborting.

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/dpatel/ex-test.retry

10.13.106.246 : ok=2 changed=0 unreachable=0 failed=1

Incorrect value of has_2RE

Switches with a single RE return "'has_2RE': True".

For example:
ok: [switch2] => {
"msg": "{u'domain': u'example.net', u'serialnumber': u'XXX', u'ifd_style': u'SWITCH', u'version_info': {u'major': [12, 3], u'type': u'R', u'build': 6, u'minor': u'6'}, u'version_RE0': u'12.3R6.6', u'RE0': {u'status': u'OK', u'last_reboot_reason': u'0x1:power cycle/failure ', u'model': u'EX2200-48T-4G', u'up_time': u'89 days, 2 hours, 2 minutes, 9 seconds', u'mastership_state': u'master'}, u'hostname': u'switch2', u'fqdn': u'switch2', u'has_2RE': True, u'switch_style': u'VLAN', u'version': u'12.3R6.6', u'master': u'RE0', u'HOME': u'/var/home/xionox', u'model': u'EX2200-48T-4G', u'vc_capable': True, u'personality': u'SWITCH'}"
}

Same thing with a EX4200-48PX

add junos_get_config

add module that will retrieve the entire configuration and store it to file. something like:

junos_get_config:
  host={{ inventory_hostname }}
  dest=saveconfs/{{ inventory_hostname }}.conf

possible options:

format=['text' | 'xml'] - select the file format; defaults to text
timestamp=[BOOLEAN] - append a timestamp to the filename; default False

other ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.