Ansible - Deployer des services

Il existe plusieurs façon de créer un répertoire avec Ansible dans un playbook.
Base de création d’un playbook : https://n0tes.fr/2023/02/12/Ansible-Playbook/

Lancer des services

Lancer un service :

- name: Start service httpd, if not started
ansible.builtin.service:
name: httpd
state: started

Stoper un service :

- name: Stop service httpd, if started
ansible.builtin.service:
name: httpd
state: stopped

Relancer un service :

- name: Restart service httpd, in all cases
ansible.builtin.service:
name: httpd
state: restarted

Recharger la configuration d’un service :

- name: Reload service httpd, in all cases
ansible.builtin.service:
name: httpd
state: reloaded

Activer un service :

- name: Enable service httpd, and not touch the state
ansible.builtin.service:
name: httpd
enabled: yes

Lancer un service en précisant son emplacement :

- name: Start service foo, based on running process /usr/bin/foo
ansible.builtin.service:
name: foo
pattern: /usr/bin/foo
state: started

Relancer une interface réseau :

- name: Restart network service for interface eth0
ansible.builtin.service:
name: network
state: restarted
args: eth0

Documentation

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html

> Partager <