【问题标题】:Compare the Active Configuration to a Previous Configuration Juniper Ansible - junipernetworks.junos.junos将活动配置与以前的配置进行比较 Juniper Ansible - junipernetworks.junos.junos
【发布时间】:2021-08-04 13:38:40
【问题描述】:

我想获得配置提交到设备之前和之后的输出。

Ansible 代码:

- 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

下面的输出没有显示以前和当前提交的配置之间的差异,如果我在这里做错了什么,请帮助我。

输出:

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
        }
    }
}

我们可以使用以下命令将候选配置与之前提交的配置进行比较:

show | compare rollback rollback-number

show | compare rollback 1

输出:

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

我可以使用 juniper.device.config 模块获得预期的输出,但我需要 junipernetworks.junos.junos_config 模块。

- 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

提前致谢。

【问题讨论】:

    标签: ansible ansible-2.x juniper juniper-network-connect


    【解决方案1】:

    以某种方式修复了多次尝试的问题。

    - 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
    

    这给了我设备上最近提交的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多