【问题标题】:Issue with Ansible Check and Diff ModeAnsible 检查和差异模式的问题
【发布时间】:2020-07-14 17:50:47
【问题描述】:

我正在阅读这篇文章 (https://blog.networktocode.com/post/generating-diff-with-ansible/),其中提到我们可以同时使用检查和差异模式。我正在尝试将其用于 Cisco 和 Extreme 设备的黄金配置审计(根据设备上存在的内容审计预先决定的配置)。下面是我的剧本——

# task to audit & heal ntp configuration
- name: Set NTP template
  ios_config:
     src: "{{domain}}_{{ansible_network_os}}_ntp.cfg"
     match: line
  register: ntp_result

下面是我的模板-

ntp server 10.19.70.1

Ansible 突出显示它将更改配置。下面是我得到的结果。令人惊讶的是,我没有得到任何配置差异。

"ntp_result": {
        "ansible_facts": {
            "discovered_interpreter_python": "/usr/bin/python"
        },
        "changed": true,
        "commands": [
            "configure ntp server add x.x.x.x"
        ],
        "failed": false,
        "updates": [
            "configure ntp server add x.x.x.x"
        ],
        "warnings": [
            "unable to perform diff against running-config due to check mode"
        ]
    }

为什么我没有得到配置差异?知道有什么问题吗?

【问题讨论】:

    标签: ansible ansible-template


    【解决方案1】:

    这是模块的限制:您只能使用diff_against 选项startupintendedcheckdiff 组合,但不能使用running

    对应Ansible源码here

            if module.params['diff_against'] == 'running':
                if module.check_mode:
                    module.warn("unable to perform diff against running-config due to check mode")
    

    【讨论】:

      猜你喜欢
      • 2016-06-18
      • 1970-01-01
      • 2022-01-13
      • 2011-03-11
      • 1970-01-01
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      相关资源
      最近更新 更多