FreeKB - service module (start stop restart services chkconfig)
Ansible - service module (start stop restart services chkconfig)

The service module is used to start, stop, restart, reload, enable and disable init services. This is similar to using the chkconfig command. The become module is used to run the command as root.

In this example, the nginx web server will be stopped and disabled.

- name: stop nginx
  service:
    name: nginx
    state: stopped
    enabled: no
  become: yes
  become_user: root

 

In this example, the nginx web server will be started and enabled.

- name: stop nginx
  service:
    name: nginx
    state: started
    enabled: yes
  become: yes
  become_user: root

 

If the service was successfully stopped, started, restated, or reloaded, the play should indicate changed.

TASK [stop nginx]
changed: [server1.example.com]

 


Arguments

Additional arguments can be included. For example, with the service command, here is how you would include the "foo" argument.

service nginx start foo

 

And here is how to do the same in Ansible.

- name: stop nginx
  service:
    name: nginx
    state: started
    enabled: yes
    arguments: foo
  become: yes
  become_user: root

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter ef637 in the box below so that we can be sure you are a human.




Comments