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<3) So I uninstalled napalm-ansible and restored the other packages. Good thing i chekced the version before hand.
$ python -m pip list | grep -E 'nornir|napalm|netmiko|ansible' ansible 2.9.10 napalm 2.5.0 netmiko 2.4.2 nornir 2.4.0
So I had to check the eos_config 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.
At the end I managed to put everything together but the eos_config was failing:
TASK [11- push config] task path: xxx/testdir2/ceos-testing/ansible/playbooks/gen-config.yaml:60 fatal: [r1]: FAILED! => { "changed": false, "msg": "path specified in src not found" }
The funny thing is all other tasks that needed to use templates were using the same path and were fine:
- name: 10- merge all configs in one file
assemble:
src: "CFGS/{{ inventory_hostname }}/"
dest: "CFGS/{{ inventory_hostname }}-full.txt"
- name: 11- push config
debugger: on_failed
eos_config:
#src: "{{playbook_dir}}/../CFGS/{{ inventory_hostname }}-full.txt"
src: "../CFGS/{{ inventory_hostname }}-full.txt"
backup: yes
So I had to find out where that task was looking for the file. It seems “assemble“, “template” and “file” tasks use as pwd where I am calling the script (xxx/testdir2/ceos-testing/ansible). But “eos_config” is using where the playbook is (xxx/testdir2/ceos-testing/ansible/playbook) based on my running command “…/ansible master$ ansible-playbook playbooks/gen-config.yaml“.
So I was searching for some help and I found the playbook path and ansible search paths. So now I needed to verify that. I found some ansible debugger and examples that were really useful!
So I used “debugger: on_failed” for my task 11. And could see the path:
TASK [11- push config] task path: /home/tomas/storage/technology/arista/testdir2/ceos-testing/ansible/playbooks/gen-config.yaml:60 fatal: [r1]: FAILED! => { "changed": false, "msg": "path specified in src not found" } [r1] TASK: 11- push config (debug)> p task.args {'backup': True, 'src': '/home/tomas/storage/technology/arista/testdir2/ceos-testing/ansible/playbooks/CFGS/r1-full.txt'} [r1] TASK: 11- push config (debug)> quit User interrupted execution
So it is clear it was looking at the playbook dir.
So after fixing the path, I realised that I didn’t want to run everything and wanted to use tags so only the last part was executed.
/ansible master$ cat playbooks/gen-config.yaml ...- name: 12- display result
debug: msg: "Backup file is {{ load_config.shortname }} and result is: {{ load_config }}"
tags: push_config
... /ansible master$ ansible-playbook playbooks/gen-config.yaml --limit="r1" -vvv --tags "push_config"
One more thing, the output of ansible when you have dictionaries, it is not great. I checked this link and it is good for failures and with -vvvv. But for green outputs still not great:
TASK [12- - display result] * task path: /home/tomas/storage/technology/arista/testdir2/ceos-testing/ansible/playbooks/gen-config.yaml:61 ok: [r1] => msg: '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}' META: ran handlers META: ran handlers PLAY RECAP r1 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 (testdir2) go:1.12.5|py:3.7.3|tomas@athens:~/storage/technology/arista/testdir2/ceos-testing/ansible master$