1

I'm trying to grab some information from the output of a playbook and save in a file for review. tor.j2 is just a list of expected lines in the config: logging , ntp, spanning-tree, etc.

 tasks:
 - name: Check the config 
     nxos_config:
       src: ./tor.j2
       defaults: true
     check_mode: yes

After running the code with a -vvv verbosity the last item in there is the differences: "updates". Is there any way to grab this information so I can then save it in order to review?

Output (shortened for brevity):

changed: [switch1] => {     
  "ansible_facts": 
    "discovered_interpreter_python": "/usr/bin/python" 
…
  "updates": [
    "feature ntp"
     ] }

Thanks for any guidance.

Zeitounator
  • 1,199
  • 5
  • 12
JonC
  • 11
  • 2

1 Answers1

0

In a nutshell (untested). You can adapt to any format you want for the log file.

---
- name: Check config and log potential updates
  hosts: all
  
  tasks:
    - name: Compare target config with existing one
      cisco.nxos.nxos_config:
        src: ./tor.j2
        defaults: true
      check_mode: yes
      register: config_check

    - name: Log potential updates to a local file
      ansible.builtin.lineinfile:
        path: /tmp/config_differences.csv
        line: '"{{ inventory_hostname }}","{{ config_check.updates | to_json }}"'
      # Make sure we don't run into a write concurrency problem
      throttle: 1
      delegate_to: localhost
Zeitounator
  • 1,199
  • 5
  • 12
  • Thanks for the example, I should get a chance to try this out and will let you know. – JonC Nov 09 '22 at 13:27