简体   繁体   English

ansible-playbook 忽略“--check”参数?

[英]ansible-playbook ignores '--check' parameter?

As testing a simple Ansible playbook作为测试一个简单的 Ansible 剧本

--- 
- hosts: mikrotiks
  connection: network_cli 
  gather_facts: no 

  vars: 

    ansible_network_os: routeros 
    ansible_user: admin 

  tasks: 

  - name: Add Basic FW Rules 
    routeros_command: 
      commands: 
        - /ip firewall nat add chain=srcnat out-interface=ether1 action=masquerade

on my mikrotik router, I used the command with --check argument在我的 mikrotik 路由器上,我使用了带有--check参数的命令

ansible-playbook -i hosts mikrotik.yml --check

but it seems that tasks actually got executed.但似乎任务实际上得到了执行。

PLAY [mikrotiks] **************************************************************************************************************************************

TASK [Add Basic FW Rules] **************************************************************************************************************************************
changed: [192.168.1.82]

PLAY RECAP **************************************************************************************************************************************
192.168.1.82               : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible.cfg file is the default configuration after fresh install. ansible.cfg文件是全新安装后的默认配置。

According the documentation command module – Run commands on remote devices running MikroTik RouterOS根据文档command模块 – 在运行 MikroTik RouterOS 的远程设备上运行命令

The module always indicates a (changed) status.模块始终指示(已更改)状态。 You can use the changed_when task property to determine whether a command task actually resulted in a change or not.您可以使用changed_when任务属性来确定命令任务是否实际导致更改。

Since the module is part of the community.routeros collection I had a short look into the source there and found that is supporting check_mode according由于该模块是community.routeros 集合的一部分,因此我简要查看了那里的源代码发现它支持check_mode

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

So you will need to follow up with defining "changed" .所以你需要跟进定义 "changed"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM