ansibleansible-2.xjuniperjuniper-network-connect

Compare the Active Configuration to a Previous Configuration Juniper Ansible - junipernetworks.junos.junos


I want to get output of Before and After Configuration commits to device.

Ansible Code :

- name: Get device information
  hosts: working_hosts
  connection: local
  gather_facts: false

  vars:
    ansible_network_os: junipernetworks.junos.junos
    connection_info:
      port: '{{ ansible_ssh_port }}'
      user: '{{ ansible_ssh_user }}'
      passwd: '{{ ansible_ssh_pass }}'
      
  tasks:
    - name: load configure lines into device and commit to device
      junipernetworks.junos.junos_config:
        update: 'merge'
        lines:
        - set security address-book global address 10.xxx.x.xxx 10.xxx.x.xxx/xx

        check_commit: yes
        confirm_commit: yes
      register: junos_output
      diff: true

    - debug:
        var: junos_output

Below output not showing diff between previous and current committed configurations, help me if i am doing any thing wrong here.

Output:

ok: [xx.xx.xxx.xx] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "backup_options": null,
            "check_commit": true,
            "comment": "configured by junos_config",
            "confirm": 0,
            "confirm_commit": false,
            "lines": [
                "set security address-book global address 10.xxx.x.xxx 10.xxx.x.xxx/xx"
            ],
            "provider": null,
            "replace": null,
            "rollback": null,
            "src": null,
            "src_format": null,
            "update": "merge",
            "zeroize": false
        }
    }
}

We can compare the candidate configuration to a previously committed configuration by using the following commands:

show | compare rollback rollback-number

show | compare rollback 1

Output:

[edit security address-book global]
+    address xx.xxx.xx.xx { ... }
+    address xx.xxx.xx.xx {
+        xx.xxx.x.xxx/xx;
+    }

I can able to get output as expected using juniper.device.config module but i need it with junipernetworks.junos.junos_config module.

- name: Print diff between current and rollback 1. No check. No commit.
  juniper.device.config:
    rollback: 1
    diff: true
    check: false
    commit: false
  register: response

- name: Print the msg.
  debug:
    var: response.diff_lines

Thanks in advance.


Solution

  • Fixed issue somehow with multiple tries.

    - name: Load configure lines into device
      junipernetworks.junos.junos_config:
        lines:
          - set security address-book global address 10.xxx.x.xxx 10.xxx.x.xxx/xx
    
        confirm_commit: yes
      register: device_status
      ignore_errors: yes
    
    - name: Compare rollback the configuration
      junipernetworks.junos.junos_config:
        rollback: 1
        check_commit: no
        confirm_commit: no
      diff: yes
      register: status_message
      when: device_status.failed is false
    

    this gives me recent committed output on the device.