Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make this ansible chkconfig task idempotent ?

I have a ansible task like this in my playbook to be run against a centos server:

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

This task changes every time I run it. How do I make this task pass the idempotency test ?

like image 655
Muhammad Lukman Low Avatar asked Jun 04 '16 02:06

Muhammad Lukman Low


1 Answers

The best option is to use the enabled=yes with service module:

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

Hope that help you.

like image 136
Arbab Nazar Avatar answered Oct 03 '22 07:10

Arbab Nazar