[INFO] Création du rôle #1

Merged
pulsar merged 1 commits from alpha into master 2023-05-24 10:32:39 +00:00
7 changed files with 151 additions and 3 deletions

View File

@ -1,3 +1,73 @@
# role_modele
# role_apt
Modèle
Rôle de configuration du gestionnaire de paquet *apt* et de déploiement/suppression de paquets.
## Variables
### apt_distribution_name
Nom de la distribution utilisée.
<span style="text-decoration: underline">Valeur par défaut:</span> `debian`
### apt_distribution_release
Nom de la version de la distribution utilisée.
<span style="text-decoration: underline">Valeur par défaut:</span> `bullseye`
### apt_distribution_sections
Sections où seront chercher les paquets (exemple : `main contrib non-free`).
<span style="text-decoration: underline">Valeur par défaut:</span> `main`
### apt_remove
Liste de paquets qui seront désinstallés.
<span style="text-decoration: underline">Valeur par défaut:</span> aucune
### apt_install
Liste de paquets qui seront installés.
<span style="text-decoration: underline">Valeur par défaut:</span> aucune
## Exemple d'utilisation
### inventory.yml
```yaml
---
all:
hosts:
host1.ykn.local:
```
### group_vars/all.yml
```yaml
---
apt_remove:
- cloud-guest-utils
- cloud-init
apt_install:
- fail2ban
- nftables
- tmux
```
### playbook.yml
```yaml
---
- hosts: 'all'
roles:
- name: apt
```

9
defaults/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
# defaults file for apt
apt_distribution_name: debian
apt_distribution_release: bullseye
apt_distribution_sections: main
apt_remove: []
apt_install: []

View File

@ -1,7 +1,7 @@
galaxy_info:
namespace: ykn
author: pulsar89.5
description: Rôle modèle
description: Configurer apt et gérer les paquets communs
license: GPL-3.0-or-later

49
tasks/main.yml Normal file
View File

@ -0,0 +1,49 @@
---
# tasks file for apt
- name: Déployer la configuration du gestionnaire
ansible.builtin.template:
src: apt.conf.j2
dest: /etc/apt/apt.conf.d/99-custom
owner: root
group: root
mode: u=rw,g=r,o=r
become: true
- name: Déployer la configuration des sources
ansible.builtin.template:
src: sources.list.j2
dest: /etc/apt/sources.list
owner: root
group: root
mode: u=rw,g=r,o=r
become: true
- name: Mettre à jour le cache
ansible.builtin.apt:
name: sudo
become: true
- name: Installer sudo
ansible.builtin.apt:
name: sudo
become: true
- name: Désinstaller les paquets communs
ansible.builtin.apt:
state: absent
purge: true
autoremove: true
name: "{{ apt_remove }}"
become: true
- name: Mettre à jour la distribution
become: true
ansible.builtin.apt:
update_cache: true
upgrade: dist
- name: Installer les paquets communs
ansible.builtin.apt:
name: "{{ apt_install }}"
become: true

8
templates/apt.conf.j2 Normal file
View File

@ -0,0 +1,8 @@
# {{ ansible_managed }}
APT::Install-Recommends "false";
APT::Install-Suggests "false";
APT::Get::Show-Versions "true";
APT::Get::Show-Upgraded "true";
APT::Get::Purge "true";
APT::Get::List-Cleanup "true";

View File

@ -0,0 +1,3 @@
# {{ ansible_managed }}
{{ apt_repositories[apt_distribution_name] }}

9
vars/main.yml Normal file
View File

@ -0,0 +1,9 @@
---
# vars file for apt
apt_repositories:
debian: |
deb http://deb.debian.org/debian {{ apt_distribution_release }} {{ apt_distribution_sections }}
deb http://security.debian.org/debian-security {{ apt_distribution_release }}-security {{ apt_distribution_sections }}
deb http://deb.debian.org/debian {{ apt_distribution_release }}-updates {{ apt_distribution_sections }}
deb https://deb.debian.org/debian/ {{ apt_distribution_release }}-backports {{ apt_distribution_sections }}