From df8580e1a9b715442b4ce3c6c2b4f09688e212c2 Mon Sep 17 00:00:00 2001 From: egvimo Date: Sun, 14 Feb 2021 15:31:51 +0000 Subject: [PATCH] Add packages tasks to system role --- molecule/system/converge.yml | 10 ++++++++++ molecule/system/molecule.yml | 1 + molecule/system/prepare.yml | 12 ++++++++++++ roles/system/README.md | 8 +++++--- roles/system/defaults/main.yml | 2 ++ roles/system/tasks/main.yml | 1 + roles/system/tasks/packages.yml | 13 +++++++++++++ 7 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 molecule/system/prepare.yml create mode 100644 roles/system/tasks/packages.yml diff --git a/molecule/system/converge.yml b/molecule/system/converge.yml index b3edee7..cd12688 100644 --- a/molecule/system/converge.yml +++ b/molecule/system/converge.yml @@ -5,3 +5,13 @@ - name: Include role include_role: name: system + + - name: Include role + include_role: + name: system + vars: + system_packages_to_remove: + - git + - gnupg + system_packages_to_install: + - screen diff --git a/molecule/system/molecule.yml b/molecule/system/molecule.yml index 19c9c62..cad1693 100644 --- a/molecule/system/molecule.yml +++ b/molecule/system/molecule.yml @@ -8,6 +8,7 @@ platforms: image: ubuntu:latest provisioner: name: ansible + prepare: prepare.yml env: ANSIBLE_ROLES_PATH: ${MOLECULE_PROJECT_DIRECTORY}/roles verifier: diff --git a/molecule/system/prepare.yml b/molecule/system/prepare.yml new file mode 100644 index 0000000..fb89f59 --- /dev/null +++ b/molecule/system/prepare.yml @@ -0,0 +1,12 @@ +--- +- name: Prepare + hosts: all + gather_facts: False + tasks: + - name: Install dependencies + ansible.builtin.apt: + pkg: + - git + - gnupg + update_cache: yes + state: present diff --git a/roles/system/README.md b/roles/system/README.md index aa1a425..124553e 100644 --- a/roles/system/README.md +++ b/roles/system/README.md @@ -4,11 +4,13 @@ Ansible role to perform general system related tasks like updateing or installin ## Role Variables -| Variable | Default value | Description | -| -------- | ------------- | ----------- | -| - | - | - | +| Variable | Default value | Description | +| -------------------------- | ------------- | ------------------- | +| system_packages_to_remove | [] | Packages to remove | +| system_packages_to_install | [] | Packages to install | ## Tags - `system` - `system_update` +- `system_packages` diff --git a/roles/system/defaults/main.yml b/roles/system/defaults/main.yml index ed97d53..0f4d767 100644 --- a/roles/system/defaults/main.yml +++ b/roles/system/defaults/main.yml @@ -1 +1,3 @@ --- +system_packages_to_remove: [] +system_packages_to_install: [] diff --git a/roles/system/tasks/main.yml b/roles/system/tasks/main.yml index 9be922b..d45bb10 100644 --- a/roles/system/tasks/main.yml +++ b/roles/system/tasks/main.yml @@ -1,4 +1,5 @@ --- - block: - import_tasks: update.yml + - import_tasks: packages.yml tags: system diff --git a/roles/system/tasks/packages.yml b/roles/system/tasks/packages.yml new file mode 100644 index 0000000..646fb95 --- /dev/null +++ b/roles/system/tasks/packages.yml @@ -0,0 +1,13 @@ +--- +- block: + - name: Remove packages + apt: + pkg: "{{ system_packages_to_remove }}" + state: absent + + - name: Install packages + apt: + pkg: "{{ system_packages_to_install }}" + state: present + become: yes + tags: system_packages