这就是我所拥有的
- name: disable os firewall - firewalld
systemd:
name: firewalld
state: stopped
enabled: no
此任务在
firewalld
的主机上运行良好软件包已安装,但在未安装的主机上失败。确保它可以处理没有
firewalld
的主机的最佳简单方法是什么?安装了吗?我不想使用任何 CMDB,因为它是一个额外的设置。另外,我希望任务是幂等的;使用 shell 命令,如 dpkg
或 rpm
查询是否 firewalld
已安装使 ansible playbook 摘要报告发生了我不想要的更改。
最佳答案
这是一个使用 failed_when:
的示例.虽然它每次都运行,但如果没有安装包,它会忽略失败:
- name: Stop and disable chrony service
service:
name: chronyd
enabled: no
state: stopped
register: chronyd_service_result
failed_when: "chronyd_service_result is failed and 'Could not find the requested service' not in chronyd_service_result.msg"
关于ansible - 仅当安装了软件包时才禁用 systemd 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968364/