From c37c4bdd1cca295985636d697952a0dbb2ecd702 Mon Sep 17 00:00:00 2001 From: "pulsar89.5" Date: Mon, 24 Oct 2022 16:02:08 +0200 Subject: [PATCH] =?UTF-8?q?[INFO]=20Cr=C3=A9ation=20du=20r=C3=B4le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 74 +++++++++++++++++++++++++++++++++++++-- defaults/main.yml | 9 +++++ meta/main.yml | 2 +- tasks/main.yml | 49 ++++++++++++++++++++++++++ templates/apt.conf.j2 | 8 +++++ templates/sources.list.j2 | 3 ++ vars/main.yml | 9 +++++ 7 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 defaults/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/apt.conf.j2 create mode 100644 templates/sources.list.j2 create mode 100644 vars/main.yml diff --git a/README.md b/README.md index 3edfbf7..09df3a4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,73 @@ -# role_modele +# role_apt -Modèle \ No newline at end of file +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. + +Valeur par défaut: `debian` + +### apt_distribution_release + +Nom de la version de la distribution utilisée. + +Valeur par défaut: `bullseye` + +### apt_distribution_sections + +Sections où seront chercher les paquets (exemple : `main contrib non-free`). + +Valeur par défaut: `main` + +### apt_remove + +Liste de paquets qui seront désinstallés. + +Valeur par défaut: aucune + +### apt_install + +Liste de paquets qui seront installés. + +Valeur par défaut: 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 +``` diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..c6c4b28 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +--- +# defaults file for apt + +apt_distribution_name: debian +apt_distribution_release: bullseye +apt_distribution_sections: main + +apt_remove: [] +apt_install: [] diff --git a/meta/main.yml b/meta/main.yml index c58bebf..75764d6 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -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 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..78fe938 --- /dev/null +++ b/tasks/main.yml @@ -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 diff --git a/templates/apt.conf.j2 b/templates/apt.conf.j2 new file mode 100644 index 0000000..203286f --- /dev/null +++ b/templates/apt.conf.j2 @@ -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"; diff --git a/templates/sources.list.j2 b/templates/sources.list.j2 new file mode 100644 index 0000000..10a0338 --- /dev/null +++ b/templates/sources.list.j2 @@ -0,0 +1,3 @@ +# {{ ansible_managed }} + +{{ apt_repositories[apt_distribution_name] }} diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..3a9e94d --- /dev/null +++ b/vars/main.yml @@ -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 }}