Ansible:当我禁用防火墙时,状态更改总是显示

Ansible: Status changed is always showed when I disable firewall

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

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

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

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

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

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

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

来自Overriding The Changed Result

When a shell/command or other module runs it will typically report “changed” status based on whether it thinks it affected machine state.

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

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