{"id":302,"date":"2020-07-16T18:37:29","date_gmt":"2020-07-16T17:37:29","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=302"},"modified":"2020-07-17T20:20:54","modified_gmt":"2020-07-17T19:20:54","slug":"ansible-troubleshooting-2","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2020\/07\/16\/ansible-troubleshooting-2\/","title":{"rendered":"Ansible Troubleshooting 2"},"content":{"rendered":"\n<p>Today I was trying to write a playbook to push config to Arista devices. <\/p>\n\n\n\n<p>Initially I wanted to use napalm module to push the config (as I have done with nornir) but it seems the napalm-ansible module requires napalm3 and netmiko3 and that breaks my nornir2.4 ( that requires napalm&lt;3) So I uninstalled napalm-ansible and restored the other packages. Good thing i chekced the version before hand.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ python -m pip list | grep -E 'nornir|napalm|netmiko|ansible'\nansible 2.9.10\nnapalm 2.5.0\nnetmiko 2.4.2\nnornir 2.4.0<\/pre>\n\n\n\n<p>So I had to check the <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/modules\/eos_config_module.html\">eos_config<\/a> module. I think the napalm-ansible module is more powerful as it uses diff and sessions provided by Arista.  As far as I can see, there is no option to say to the module to just make a dry run.<\/p>\n\n\n\n<p>At the end I managed to put everything together but the eos_config was failing:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">TASK [11- push config]\ntask path: xxx\/testdir2\/ceos-testing\/ansible\/playbooks\/gen-config.yaml:60\nfatal: [r1]: FAILED! => {\n\"changed\": false,\n\"msg\": \"path specified in src not found\"\n}<\/pre>\n\n\n\n<p>The funny thing is all other tasks that needed to use templates were using the same path and were fine:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>- name: 10- merge all configs in one file\n  assemble:\n    src: \"CFGS\/{{ inventory_hostname }}\/\" \n    dest: \"CFGS\/{{ inventory_hostname }}-full.txt\"\n\n- name: 11- push config\n  debugger: on_failed\n  eos_config:\n    #src: \"{{playbook_dir}}\/..\/CFGS\/{{ inventory_hostname }}-full.txt\"\n    src: \"..\/CFGS\/{{ inventory_hostname }}-full.txt\"\n    backup: yes<\/code><\/pre>\n\n\n\n<p>So I had to find out where that task was looking for the file. It seems &#8220;<em>assemble<\/em>&#8220;, &#8220;<em>template<\/em>&#8221; and &#8220;<em>file<\/em>&#8221; tasks use as <strong>pwd<\/strong> where I am calling the script (<em>xxx\/testdir2\/ceos-testing\/ansible<\/em>). But &#8220;<em>eos_config<\/em>&#8221; is using where the playbook is (<em>xxx\/testdir2\/ceos-testing\/ansible\/playbook<\/em>) based on my running command &#8220;&#8230;<em>\/ansible master$ ansible-playbook playbooks\/gen-config.yaml<\/em>&#8220;.<\/p>\n\n\n\n<p>So I was searching for some help and I found the playbook <a href=\"https:\/\/stackoverflow.com\/questions\/30787273\/variable-that-has-the-path-to-the-current-ansible-playbook-that-is-executing\">path<\/a> and <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/playbook_pathing.html\">ansible search paths<\/a>. So now I needed to verify that. I found some ansible <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/playbooks_debugger.html\">debugger<\/a> and <a href=\"https:\/\/blog.codecentric.de\/en\/2017\/06\/debug-ansible-playbooks-like-pro\/\">examples<\/a> that were really useful!<\/p>\n\n\n\n<p>So I used &#8220;debugger: on_failed&#8221; for my task 11. And could see the path:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">TASK [11- push config]\ntask path: \/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/gen-config.yaml:60\nfatal: [r1]: FAILED! => {\n\"changed\": false,\n\"msg\": \"path specified in src not found\"\n}\n<strong>[r1] TASK: 11- push config (debug)> p task.args<\/strong>\n{'backup': True,\n'<em>src<\/em>': '<em>\/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/CFGS\/r1-full.txt<\/em>'}\n<strong>[r1] TASK: 11- push config (debug)> quit<\/strong>\nUser interrupted execution<\/pre>\n\n\n\n<p>So it is clear it was looking at the playbook dir. <\/p>\n\n\n\n<p>So after fixing the path, I realised that I didn&#8217;t want to run everything and wanted to use  <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/playbooks_tags.html\">tags<\/a> so only the last part was executed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/ansible master$ cat playbooks\/gen-config.yaml\n...\n<code>- name: 12- display result <\/code>\n  <code>debug: msg: \"Backup file is {{ load_config.shortname }} and result is: {{ load_config }}\" <\/code>\n  <code><strong>tags<\/strong>: <strong>push_config<\/strong><\/code>\n...\n\n\/ansible master$ ansible-playbook playbooks\/gen-config.yaml --limit=\"r1\" -vvv --<strong>tags<\/strong> \"push_config\"<\/pre>\n\n\n\n<p>One more thing, the output of ansible when you have dictionaries, it is not great. I checked this <a href=\"https:\/\/stackoverflow.com\/questions\/50009505\/ansible-stdout-formatting\/50017860\">link<\/a> and it is good for failures and with -vvvv.  But for green outputs still not great:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">TASK [12- - display result] *\ntask path: \/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/gen-config.yaml:61\nok: [r1] =>\nmsg: 'Backup file is \/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/backup\/r1_config and result is: {''changed'': True, ''commands'': [''interface Ethernet1'', ''no shutdown'', ''interface Ethernet2'', ''no shutdown'', ''router bgp 100'', ''neighbor AS100-CORE password mpls-sr''], ''updates'': [''interface Ethernet1'', ''no shutdown'', ''interface Ethernet2'', ''no shutdown'', ''router bgp 100'', ''neighbor AS100-CORE password mpls-sr''], ''session'': ''ansible_1594920727'', ''backup_path'': ''\/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/backup\/r1_config.2020-07-16@18:32:07'', ''date'': ''2020-07-16'', ''time'': ''18:32:07'', ''shortname'': ''\/home\/tomas\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible\/playbooks\/backup\/r1_config'', ''filename'': ''r1_config.2020-07-16@18:32:07'', ''failed'': False}'\nMETA: ran handlers\nMETA: ran handlers\nPLAY RECAP\nr1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0\n(testdir2) go:1.12.5|py:3.7.3|tomas@athens:~\/storage\/technology\/arista\/testdir2\/ceos-testing\/ansible master$<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I was trying to write a playbook to push config to Arista devices. Initially I wanted to use napalm module to push the config (as I have done with nornir) but it seems the napalm-ansible module requires napalm3 and netmiko3 and that breaks my nornir2.4 ( that requires napalm&lt;3) So I uninstalled napalm-ansible and &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2020\/07\/16\/ansible-troubleshooting-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Ansible Troubleshooting 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-302","post","type-post","status-publish","format-standard","hentry","category-automation"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=302"}],"version-history":[{"count":2,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":313,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/302\/revisions\/313"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}