Ansible for Juniper EX2200-c

In my home lab I have 4 Juniper in a virtual chassis. I currently use fedora 24 as my host system so I had to install some binaries and fix some code before I got this running. First you have to install the latest stable ansible version.

Then you need junos-eznc. For fedora run the following command

[dobby@dobby ansible]$ sudo pip install junos-eznc

Once I’ve installed the so called pre req I run the following ansible playbook.

- hosts: juniper
  gather_facts: no
  connection: local

  vars:
    cli:
      host: "{{ inventory_hostname }} "
      username: juniper
      password: password
      port: 22
      transport: netconf

  tasks:
    - name: run show version
      junos_command:
        commands: show version
        provider: "{{ cli }}"

After ansible run I got the following error message:

[dobby@dobby ansible]$ ansible-playbook -i inventory/ junos.yaml -vv
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: junos.yaml ***********************************************************
1 plays in junos.yaml

PLAY [juniper] *****************************************************************

TASK [run show version] ********************************************************
task path: /home/dobby/Development/ansible/junos.yaml:18
fatal: [juniper]: FAILED! => {"changed": false, "failed": true, "msg": "jxmlease is required but does not appear to be installed.  It can be installed using `pip install jxmlease`"}
	to retry, use: --limit @/home/dobby/Development/ansible/junos.retry

PLAY RECAP *********************************************************************
juniper                    : ok=0    changed=0    unreachable=0    failed=1   

Next step was to install jxmlease

[dobby@dobby ansible]$ sudo pip install jxmlease
Collecting jxmlease
  Using cached jxmlease-1.0.1-py2.py3-none-any.whl
Installing collected packages: jxmlease
Successfully installed jxmlease-1.0.1
You are using pip version 8.0.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

After that I run the playbook again and ran into another hurdle.

[dobby@dobby ansible]$ ansible-playbook -i inventory/ junos.yaml -vv
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: junos.yaml ***********************************************************
1 plays in junos.yaml

PLAY [juniper] *****************************************************************

TASK [run show version] ********************************************************
task path: /home/dobby/Development/ansible/junos.yaml:18
fatal: [juniper]: FAILED! => {"changed": false, "failed": true, "msg": "unable to connect to 192.168.99.23: ConnectError(host: 192.168.99.23, msg: CTR mode needs counter parameter, not IV)"}
	to retry, use: --limit @/home/dobby/Development/ansible/junos.retry

PLAY RECAP *********************************************************************
juniper

A quick google search for “msg: CTR mode needs counter parameter, not IV)” revealed that the file /usr/lib/python2.7/site-packages/paramiko/transport.py needs patching as the value of IV should be an empty string for this to work. So on line 1649 patch the following:

return self._cipher_info[name]['class'].new(key, self._cipher_info[name]['mode'], iv, counter)
to 
return self._cipher_info[name]['class'].new(key, self._cipher_info[name]['mode'], '', counter)

After that I was successful in running the playbook.

[dobby@dobby ansible]$ ansible-playbook -i inventory/ junos.yaml -vv
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: junos.yaml ***********************************************************
1 plays in junos.yaml

PLAY [juniper] *****************************************************************

TASK [run show version] ********************************************************
task path: /home/dobby/Development/ansible/junos.yaml:18
ok: [juniper] => {"changed": false, "stdout": [{"multi-routing-engine-results": {"multi-routing-engine-item": [{"re-name": "fpc0", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc1", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc2", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc3", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}]}}], "stdout_lines": [{"multi-routing-engine-results": {"multi-routing-engine-item": [{"re-name": "fpc0", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc1", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc2", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}, {"re-name": "fpc3", "software-information": {"host-name": "switch0", "package-information": [{"comment": "JUNOS Base OS boot [12.3R12.4]", "name": "junos"}, {"comment": "JUNOS Base OS Software Suite [12.3R12.4]", "name": "jbase"}, {"comment": "JUNOS Kernel Software Suite [12.3R12.4]", "name": "jkernel-ex-2200"}, {"comment": "JUNOS Crypto Software Suite [12.3R12.4]", "name": "jcrypto-ex"}, {"comment": "JUNOS Online Documentation [12.3R12.4]", "name": "jdocs-ex"}, {"comment": "JUNOS Enterprise Software Suite [12.3R12.4]", "name": "jswitch-ex"}, {"comment": "JUNOS Packet Forwarding Engine Enterprise Software Suite [12.3R12.4]", "name": "jpfe-ex22x"}, {"comment": "JUNOS Routing Software Suite [12.3R12.4]", "name": "jroute-ex"}, {"comment": "JUNOS Web Management [12.3R12.4]", "name": "jweb-ex"}, {"comment": "JUNOS FIPS mode utilities [12.3R12.4]", "name": "fips-mode-arm"}], "product-model": "ex2200-c-12t-2g", "product-name": "ex2200-c-12t-2g"}}]}}], "warnings": []}

PLAY RECAP *********************************************************************
juniper                    : ok=1    changed=0    unreachable=0    failed=0