Ansible playbook 不更改文件,但返回成功

标签 ansible

我正在使用 ansible 在 25 台服务器上禁用 selinux。

- name: disable selinux
  selinux: state=disabled

服务器在主机文件中定义,我正在运行剧本

ansible-playbook -v -i hosts ansible/server-prepare.yml

输出如下所示:

GATHERING FACTS ***************************************************************
ok: [10.0.0.10]
(... other servers ...)

TASK: [prepare | disable selinux] *********************************************
changed: [10.0.0.10] => {"changed": true, "configfile": "/etc/selinux/config", "msg": "state change will take effect next reboot", "policy": "targeted", "state": "disabled"}
(... other servers ...)

但是,主机 10.0.0.10 上的配置文件中的值并未更改:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing

我知道,更改配置文件后需要重新启动,但配置文件根本没有更改。 对于 playbook 中的所有命令,ansible 返回成功,但没有任何效果。

目前,我只尝试将 -v 添加到 ansible-playbook 命令中。我还有其他选项来调试这个吗?我正在使用 ansible-playbook 1.9.2

最佳答案

为了测试我添加了:

connection: local

这导致对本地主机进行更改,即使 ansible 报告在其他 ip 上运行。

关于Ansible playbook 不更改文件,但返回成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31721750/

相关文章:

azure - 使用 for_each 时从 Terraform 创建库存文件

regex - 来自标准输出的ansible解析文本字符串

ansible - 如何在 Ansible 中向已知主机添加 SSH 指纹?

当变量具有默认值时,Ansible playbook 条件失败

ubuntu - 如何使用ansible在目标上提取war文件

ansible - AWX - 使用 Ansible 集合

mysql - 使用Icinga2 Web2的IDO DB中没有历史数据

ansible - 使用 jmespath 从 dict 中提取嵌套数组

ansible - 失败的! => {"changed": false, "msg": "apt cache update failed"} 尝试时

loops - 具有动态变量的 Ansible 循环任务