From e0838a61b9a3dbcb2e7e27e85a45d70a3465d638 Mon Sep 17 00:00:00 2001 From: Adrien Date: Sun, 5 Apr 2020 23:29:22 +0200 Subject: [PATCH] Play with tags --- defaults/main.yml | 1 + tasks/install.yml | 10 ++++++++++ tasks/main.yml | 19 +++++++++++++------ tasks/uninstall.yml | 30 ++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 defaults/main.yml create mode 100644 tasks/install.yml create mode 100644 tasks/uninstall.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..545a339 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1 @@ +ansible_uninstall: false \ No newline at end of file diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..4b1edd6 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,10 @@ +--- + - name: Define repo for {{ ansible_os_family }} + include_tasks: add_repo_{{ ansible_os_family }}.yml + tags: + - config + + - name: Install packages + package: name='{{ ansible_packages }}' state=latest update_cache=yes + tags: + - installation diff --git a/tasks/main.yml b/tasks/main.yml index 2f1ce57..4dbbc58 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,17 @@ --- -- name: Include vars for {{ ansible_os_family }} - include_vars: "{{ ansible_os_family }}.yml" +- block: + - name: Include vars for {{ ansible_os_family }} + include_vars: "{{ ansible_os_family }}.yml" -- name: Define repo for {{ ansible_os_family }} - include_tasks: add_repo_{{ ansible_os_family }}.yml + - name: Install Ansible + include_tasks: "install.yml" + when: + - not ansible_uninstall|bool -- name: Install packages - package: name='{{ ansible_packages }}' state=latest update_cache=yes + - name: UnInstall Ansible + include_tasks: "uninstall.yml" + when: + - ansible_uninstall|bool + tags: + - ansible \ No newline at end of file diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml new file mode 100644 index 0000000..fb73b51 --- /dev/null +++ b/tasks/uninstall.yml @@ -0,0 +1,30 @@ +--- + - name: Define repo for {{ ansible_os_family }} + include_tasks: add_repo_{{ ansible_os_family }}.yml + + - name: Remove Ansible's files + file: + path: "/etc/yum.repos.d/ansible.repo" + state: absent + when: + - ansible_os_family == 'RedHat' + + - name: Registering Ubuntu Ansible repository + apt_repository: + repo: ppa:ansible/ansible + state: absent + update_cache: yes + when: + - ansible_distribution == "Ubuntu" + + - name: Registering Debian Ansible repository + apt_repository: + repo: deb http://ppa.launchpad.net/ansible/ansible/ubuntu {{ ansible_distribution_name }} main + filename: ansible.list + state: absent + update_cache: yes + when: + - ansible_distribution == "Debian" + + - name: Remove Ansible's packages + package: name='{{ ansible_packages }}' state=absent update_cache=yes