End-of-Day 1 Exercise · Ansible Playbooks
Ansible Playbooks
Assignment
- Write a playbook that:
- Removes nginx from every host on which it is installed.
- Removes all files used by nginx (e.g. index.html).
Minimal example
- name: Remove and purge nginx
hosts: web
become: true
serial: 1
vars:
nginx_packages:
- nginx
- nginx-common
- nginx-core
- nginx-full
- nginx-light
tasks:
- name: Remove nginx
ansible.builtin.apt:
name: "{{ nginx_packages }}"
state: absent
purge: true
autoremove: true
update_cache: true
tags: [uninstall]
- name: Remove the home page
become: yes
file:
path: "{{ item }}"
state: absent
loop:
- /etc/nginx
- /var/log/nginx
- /var/www/html
tags: [purge]