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

tasks:
– name: diff against running config
voss_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
ssh
ip pim enable
@@ -47,4 +48,5 @@
router ospf
router rip
exit
-end
\ No newline at end of file
+end
+VSP-8284XSQ:1#
\ No newline at end of file

Search for highlighted text in Word

Search a document for highlighted text (any colour) using Find with Advanced option, leave “Find what:” blank and select Highlight in Format list.

So, if you have a config.cfg from an old VOSS switch which you want to re-use on a new switch you can highlight the lines that you need to change and search for them using this method later when you are ready to update it.

The final updated file can be copied to VOSS switches and then loaded using the source command.

If you use source config.cfg debug stop syntax, it will display commands (line-by-line) and if any have invalid syntax, it will stop and the last one will only parse and test but not apply. If you remove “syntax” it will attempt to apply all commands.

Or copy the file and boot with it with the no boot config flags verify-config set. It will keep reading the file even if it hits something it does not like.

Since VOSS release 8.2 a new feature was added for management. The clip or VLAN IP used for management will need to be converted to SMI. Insert the line migrate-to-mgmt under either the “interface loopback x” or “interface vlan x” lines in the config you are using.

Compare original config with running-config and amend where needed.

Create a list of VLAN commands in Excel

First, open a new Excel workbook and import the list of VLANs from the “show interface gigabit vlan” command in VOSS. Prepare the data in Notepad ++ by inserting a “=” as a column break between each word to help with the import into columns. You want a single cell with a list of VLANs.

Identify a free cell in the sheet and use the Data tab Text to Column tool to split the list of comma separated VLANs into new columns.

Select all of the VLAN columns and paste into a new cell using Transpose which will create a list of VLANs in a single column.

Always ensure the columns are set as type “Text”.

Insert a new column alongside the previous one and add the interface number alongside each VLAN.

Then we can use the concatenate formula to combine the VLANs and interface at the end of the string “vlan members add”.

For example, the formula would be =CONCATENATE(“vlan members add “,O2,” “,P2) placed in the adjacent cell in a new column alongside the VLAN and Interface columns. We can then select the cell and drag it down the rest of the column to create the list of VLAN commands needed to add a long list of VLANs to an individual port.

Alternatively, use GREP to extract all of the “vlan members” lines from the saved config file and import into Excel (into columns). Add a column alongside “members” which can contain “remove” or “add”. If needed remove the slot and “/” characters from the port numbers if applying on a switch with a different format. Higher speed ports may need changing manually as well. Create a new column which concatenates the cells to build the commands to assign VLANs to ports. This method probably cleaner.