如何使这个ansible chkconfig任务幂等?

时间:2016-06-04 02:50:36

标签: centos ansible ansible-playbook

我在我的剧本中有一个像这样的ansible任务对着centos服务器运行:

   - name: Enable services for automatic start
     action: command /sbin/chkconfig {{ item }} on
     with_items:
       - nginx
       - postgresql

每次运行时,此任务都会更改。如何让这个任务通过幂等性测试?

1 个答案:

答案 0 :(得分:13)

最佳选择是将enabled=yes与服务模块一起使用:

- name: Enable services for automatic start
  service:
    name: "{{ item }}"
    enabled: yes
  with_items:
    - nginx
    - postgresql

希望能帮助你。

相关问题