Identifying differences on a file using Ansible

Compare differences in a configuration file using the following play-book:

– hosts: voss
gather_facts: no
become: yes

– name: diff against running config
diff_against: intended
intended_config: “{{ lookup(‘file’, ‘vsp.cfg’) }}”

Sample output where I changed the prompt name on the switch and beforehand captured the running config (terminal more disable) to a file ‘vsp.cfg’.

$ ansible-playbook test-diff.yml -l voss –diff


— before
+++ after
@@ -1,7 +1,8 @@
+=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2022.02.20 16:35:12 =~=~=~=~=~=~=~=~=~=~=~=
+show run
config terminal
no boot config flags spbm-config-mode
boot config flags sshd
-prompt “switch-01”
password password-history 3
ip pim enable
@@ -47,4 +48,5 @@
router ospf
router rip
\ No newline at end of file
\ No newline at end of file

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s