Files
2026-10-18 16:41:04 +02:00

44 lines
1.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
- name: "how to use block"
hosts: ansible.debian ansible.ubuntu
tasks:
- name: "install nginx"
# Ce qui est prévu
block:
- name: "install nginx"
ansible.builtin.apt:
name: nginx
state: present
- name: configure nginx
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
- name: restart nginx
ansible.builtin.service:
name: nginx
state: restarted
# Ce qui est prévu en cas d’erreur
rescue:
- name: remove nginx conf file
ansible.builtin.file:
path: /etc/nginx/nginx.conf
state: absent
- name: remove nginx
ansible.builtin.apt:
name: nginx
state: absent
# Dans tous les cas
always:
- name: display playbook finished message
ansible.builtin.debug:
msg: 'your play was played :)'
# Commun pour toutes les tâches
become: yes