Play with tags

This commit is contained in:
Adrien Reslinger 2020-04-05 23:29:22 +02:00
parent 4ce39bb4e9
commit e0838a61b9
4 changed files with 54 additions and 6 deletions

1
defaults/main.yml Normal file
View file

@ -0,0 +1 @@
ansible_uninstall: false

10
tasks/install.yml Normal file
View file

@ -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

View file

@ -1,10 +1,17 @@
---
- name: Include vars for {{ ansible_os_family }}
- 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

30
tasks/uninstall.yml Normal file
View file

@ -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