napalm-automation/napalm-ansible

napalm-ansible shows no diffs on change

erjolb opened this issue · 7 comments

hi, running the below playbook with napalm_install_config I get no diffs back. But it works with -v though.

- name: configure access vlan
  hosts: junos ios
  gather_facts: no
  connection: local

  tasks:
    - name: build config
      template:
        src: "templates/{{ ansible_network_os }}/assign_vlan.j2"
        dest: "configs/{{ inventory_hostname }}/assign_vlan.conf"
      delegate_to: localhost
      check_mode: no

    - name: Deploy config
      napalm_install_config:
        hostname: "{{ ansible_host }}"
        username: "{{ ansible_user }}"
        dev_os: "{{ ansible_network_os }}"
        config_file: "gns3/playbooks/configs/{{ inventory_hostname }}/assign_vlan.conf"
        commit_changes: yes
        optional_args:
          allow_agent: yes

ansible-playbook -i gns3/hosts.ini gns3/playbooks/assign_vlan.yml -CD -l vqfx1,iosv1

PLAY [configure access vlan] *********************************************************************************************************************************************

TASK [build config] ******************************************************************************************************************************************************
--- before
+++ after: /Users/ebane/.ansible/tmp/ansible-local-247329_paaopz/tmp2lxl79jh/assign_vlan.j2
@@ -0,0 +1,22 @@
+interfaces {
+    xe-0/0/7 {
+        description pc1;
+        unit 0 {
+            family ethernet-switching {
+                vlan {
+                    members red;
+                }
+            }
+        }
+    }
+    xe-0/0/2 {
+        description napalm-ansible;
+        unit 0 {
+            family ethernet-switching {
+                vlan {
+                    members red;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

changed: [vqfx1 -> localhost]
--- before
+++ after: /Users/ebane/.ansible/tmp/ansible-local-247329_paaopz/tmpg7y2t3f7/assign_vlan.j2
@@ -0,0 +1,15 @@
+interface GigabitEthernet3/0
+ description PC1
+ switchport mode access
+ switchport access vlan 5
+ spanning-tree portfast
+interface GigabitEthernet3/1
+ description PC2
+ switchport mode access
+ switchport access vlan 5
+ spanning-tree portfast
+interface GigabitEthernet3/3
+ description napalm-ansible
+ switchport mode access
+ switchport access vlan 5
+ spanning-tree portfast

changed: [iosv1 -> localhost]

TASK [Deploy config] *****************************************************************************************************************************************************
changed: [vqfx1]
changed: [iosv1]

PLAY RECAP ***************************************************************************************************************************************************************
iosv1                      : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
vqfx1                      : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Playbook run took 0 days, 0 hours, 0 minutes, 27 seconds


ansible-playbook -i gns3/hosts.ini gns3/playbooks/assign_vlan.yml -CD -l vqfx1,iosv1 -v
Using /Users/ebane/Documents/ansible/ansible.cfg as config file

PLAY [configure access vlan] *********************************************************************************************************************************************

TASK [build config] ******************************************************************************************************************************************************
ok: [vqfx1 -> localhost] => {
    "changed": false,
    "checksum": "bf39284b2a659984bf8a8a2f1fc94b2467a74886",
    "dest": "configs/vqfx1/assign_vlan.conf",
    "gid": 20,
    "group": "staff",
    "mode": "0644",
    "owner": "ebane",
    "path": "configs/vqfx1/assign_vlan.conf",
    "size": 427,
    "state": "file",
    "uid": 501
}
ok: [iosv1 -> localhost] => {
    "changed": false,
    "checksum": "17283c5e761356cce2b0fe0fa28ce97b5497c488",
    "dest": "configs/iosv1/assign_vlan.conf",
    "gid": 20,
    "group": "staff",
    "mode": "0644",
    "owner": "ebane",
    "path": "configs/iosv1/assign_vlan.conf",
    "size": 371,
    "state": "file",
    "uid": 501
}

TASK [Deploy config] *****************************************************************************************************************************************************
changed: [vqfx1] => {
    "changed": true
}

MSG:

[edit interfaces xe-0/0/2]
-   description pc1;
+   description napalm-ansible;

changed: [iosv1] => {
    "changed": true
}

MSG:

+interface GigabitEthernet3/0
+ spanning-tree portfast
+interface GigabitEthernet3/1
+ spanning-tree portfast
+interface GigabitEthernet3/3
+ description napalm-ansible
+ switchport mode access
+ switchport access vlan 5
+ spanning-tree portfast


PLAY RECAP ***************************************************************************************************************************************************************
iosv1                      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
vqfx1                      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Playbook run took 0 days, 0 hours, 0 minutes, 26 seconds

this is the ansible version:
ansible --version
ansible 2.8.4
  config file = /Users/ebane/Documents/ansible/ansible.cfg
  configured module search path = ['/usr/local/lib/python3.6/site-packages/napalm_ansible/modules']
  ansible python module location = /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/ansible
  executable location = /Library/Frameworks/Python.framework/Versions/3.6/bin/ansible
  python version = 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]

Can you re-state your issue and post your ansible-playbook?

I am not sure I understand your problem.

sorry, I included the playbook now and the issue is that I do not see the difference of the change. I have to add -v to actually see what is being changed on the switches. let me know if you need more details and thanks

I think the general intent in NAPALM-ansible is to write it out to a file (similar to this).

https://github.com/ktbyers/ansible_course/blob/master/class5/collateral/video_napalm_merge/napalm_merge_1.yml

That is a merge operation and a diff being written out to a file.

according to the documentation below, isn't it supposed to return always the msg variable which shows the diff? or it means that I need to display it via the debug ansible module?

like this:
- name: print diff debug: var: output.msg

https://napalm.readthedocs.io/en/latest/integrations/ansible/modules/napalm_install_config/index.html

@erjolbane Yes we return the diff in msg from the playbook execution (I just checked the source code). You would still have to print it out using the debug module (similar to what you proposed above) or by adding -vvv to your ansible-playbook invocation.

Ansible is able to provide the diff if the full running config and the full candidate config (as interpreted by the device) are sent back in a diff key.
I have been playing with that here with a correct result:

--- before
+++ after
@@ -1,5 +1,6 @@
 interface GigabitEthernet2
+ ip address 172.20.0.1 255.255.255.0
+router bgp 65000
+ bgp log-neighbor-changes
+ neighbor 1.1.1.1 remote-as 12345
 interface GigabitEthernet2
- no ip address
-
-logging buffered 9000
\ No newline at end of file

changed: [merge.commit.change]

The difficulty is the drivers are not returning consitent diff as it is dependant of the vendor implementation, and none of the drivers returns the full candidate config.
IOS is returning a patch like string with all the deletion then all the addition to the configuration
EOS is returning a patch like string
NXOS is returning a set of commands to go from running config to intent config
Etc.

The output of the diff, as done by ansible, cannot be consistent accross different vendor.
I guess we could add a helper in napalm to parse the diff of the different vendors and have a consitent behaviour but I'm not sure it would worth the trouble.

Yes, I don't think this is really worthwhile.

As far as I can tell this is all operating per-design...though maybe not exactly how you would want it in an Ansible context.

But the diff is there including a diff that you can retrieve before commit_config using standard Ansible operations.