【问题标题】:Ansible: Status changed is always showed when I disable firewallAnsible:当我禁用防火墙时,总是显示状态改变
【发布时间】:2019-01-19 13:28:42
【问题描述】:

我尝试使用 ansible 禁用 Centos7 上的防火墙。 这有效:

  - name: turn off firewall for install
    command: systemctl disable firewalld
    become: yes

但我必须多次重新运行这个 ansible playbook,每次输出显示“changed”,而我希望这是“ok”?

TASK [turn off firewall for install] *******************************************
changed: [node1]
changed: [node2]
changed: [node3]

我错过了什么或做错了什么? 谢谢

【问题讨论】:

    标签: ansible centos7 firewall


    【解决方案1】:

    例如尝试使用systemd 模块而不是使用command

    - name: turn off firewall for install
      systemd:
       name: firewalld
       state: stopped
       enabled: false
    

    来自Overriding The Changed Result

    当一个 shell/命令或其他模块运行时,它通常会根据它是否认为它影响机器状态来报告“已更改”状态。

    要覆盖“更改”结果,使其不会出现在报告输出中或不会导致处理程序触发,您可以尝试以下操作:

    - name: turn off firewall for install
      command: systemctl disable firewalld
      become: yes
      changed_when: False
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-09
      • 2021-06-18
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      相关资源
      最近更新 更多