{"id":1947,"date":"2017-02-25T12:44:07","date_gmt":"2017-02-25T17:44:07","guid":{"rendered":"http:\/\/blog.domb.net\/?p=1947"},"modified":"2017-05-17T10:37:16","modified_gmt":"2017-05-17T14:37:16","slug":"ansible-for-juniper","status":"publish","type":"post","link":"https:\/\/blog.domb.net\/?p=1947","title":{"rendered":"Ansible for Juniper EX2200-c"},"content":{"rendered":"<p>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.<\/p>\n<p>Then you need junos-eznc. For fedora run the following command<\/p>\n<pre class=\"lang:default decode:true \">[dobby@dobby ansible]$ sudo pip install junos-eznc<\/pre>\n<p>Once I&#8217;ve installed the so called pre req I run the following ansible playbook.<\/p>\n<pre class=\"lang:default decode:true \">- hosts: juniper\r\n  gather_facts: no\r\n  connection: local\r\n\r\n  vars:\r\n    cli:\r\n      host: \"{{ inventory_hostname }} \"\r\n      username: juniper\r\n      password: password\r\n      port: 22\r\n      transport: netconf\r\n\r\n  tasks:\r\n    - name: run show version\r\n      junos_command:\r\n        commands: show version\r\n        provider: \"{{ cli }}\"<\/pre>\n<p>After ansible run I got the following error message:<\/p>\n<pre class=\"lang:default decode:true \">[dobby@dobby ansible]$ ansible-playbook -i inventory\/ junos.yaml -vv\r\nUsing \/etc\/ansible\/ansible.cfg as config file\r\n\r\nPLAYBOOK: junos.yaml ***********************************************************\r\n1 plays in junos.yaml\r\n\r\nPLAY [juniper] *****************************************************************\r\n\r\nTASK [run show version] ********************************************************\r\ntask path: \/home\/dobby\/Development\/ansible\/junos.yaml:18\r\nfatal: [juniper]: FAILED! =&gt; {\"changed\": false, \"failed\": true, \"msg\": \"jxmlease is required but does not appear to be installed.  It can be installed using `pip install jxmlease`\"}\r\n\tto retry, use: --limit @\/home\/dobby\/Development\/ansible\/junos.retry\r\n\r\nPLAY RECAP *********************************************************************\r\njuniper                    : ok=0    changed=0    unreachable=0    failed=1   \r\n<\/pre>\n<p>Next step was to install jxmlease<\/p>\n<pre class=\"lang:default decode:true \">[dobby@dobby ansible]$ sudo pip install jxmlease\r\nCollecting jxmlease\r\n  Using cached jxmlease-1.0.1-py2.py3-none-any.whl\r\nInstalling collected packages: jxmlease\r\nSuccessfully installed jxmlease-1.0.1\r\nYou are using pip version 8.0.2, however version 9.0.1 is available.\r\nYou should consider upgrading via the 'pip install --upgrade pip' command.\r\n<\/pre>\n<p>After that I run the playbook again and ran into another hurdle.<\/p>\n<pre class=\"lang:default decode:true \">[dobby@dobby ansible]$ ansible-playbook -i inventory\/ junos.yaml -vv\r\nUsing \/etc\/ansible\/ansible.cfg as config file\r\n\r\nPLAYBOOK: junos.yaml ***********************************************************\r\n1 plays in junos.yaml\r\n\r\nPLAY [juniper] *****************************************************************\r\n\r\nTASK [run show version] ********************************************************\r\ntask path: \/home\/dobby\/Development\/ansible\/junos.yaml:18\r\nfatal: [juniper]: FAILED! =&gt; {\"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)\"}\r\n\tto retry, use: --limit @\/home\/dobby\/Development\/ansible\/junos.retry\r\n\r\nPLAY RECAP *********************************************************************\r\njuniper<\/pre>\n<p>A quick google search for &#8220;msg: CTR mode needs counter parameter, not IV)&#8221; 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:<\/p>\n<pre class=\"lang:default decode:true \">return self._cipher_info[name]['class'].new(key, self._cipher_info[name]['mode'], iv, counter)\r\nto \r\nreturn self._cipher_info[name]['class'].new(key, self._cipher_info[name]['mode'], '', counter)\r\n<\/pre>\n<p>After that I was successful in running the playbook.<\/p>\n<pre class=\"lang:default decode:true \">[dobby@dobby ansible]$ ansible-playbook -i inventory\/ junos.yaml -vv\r\nUsing \/etc\/ansible\/ansible.cfg as config file\r\n\r\nPLAYBOOK: junos.yaml ***********************************************************\r\n1 plays in junos.yaml\r\n\r\nPLAY [juniper] *****************************************************************\r\n\r\nTASK [run show version] ********************************************************\r\ntask path: \/home\/dobby\/Development\/ansible\/junos.yaml:18\r\nok: [juniper] =&gt; {\"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\": []}\r\n\r\nPLAY RECAP *********************************************************************\r\njuniper                    : ok=1    changed=0    unreachable=0    failed=0   \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":2,"featured_media":2027,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[64],"tags":[67,95,94],"class_list":["post-1947","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","tag-ansible","tag-ex2200-c","tag-juniper"],"_links":{"self":[{"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/posts\/1947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.domb.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1947"}],"version-history":[{"count":7,"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/posts\/1947\/revisions"}],"predecessor-version":[{"id":2028,"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/posts\/1947\/revisions\/2028"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.domb.net\/index.php?rest_route=\/wp\/v2\/media\/2027"}],"wp:attachment":[{"href":"https:\/\/blog.domb.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.domb.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.domb.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}