0

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

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

提前致谢。

4

1 回答 1

0

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

- 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

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

于 2021-08-09T09:02:21.340 回答