I've finally found something that works
This is the playbook inclued in the role folder 'apache', which install this service
---
- name: Installation apache sur Centos et RedHat
yum:
name: httpd
state: present
when: (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat') and reponse_apache == 'oui'
I declared a variable `reponse_apache'. If the user says 'oui', the install begins
My main playbook:
---
- hosts: slaves
roles:
# - ntp
# - nmap
# - tcpdump
# - unattended-upgrades
# - traceroute
- apache
# - mysql
vars_prompt:
- name: "reponse_apache"
prompt: "Voulez vous installer apache ? Une exception pare-feu pour le service http sera créée sur les systèmes CentOS 7 (oui/non) "
private: no
- name: "reponse_mysql"
prompt: "Voulez vous installer mysql ? (oui/non) "
private: no
I created a section vars_prompt
which contains the variable reponse_apache
. I've done the same for mysql with the variable reponse_mysql
---
- name: Installation python sur les systèmes Debian et Ubuntu
apt:
name: python3
state: present
when: (ansible_distribution == 'Debian' or ansible_distribution) == 'Ubuntu' and reponse_mysql == 'oui'
- name: Installation wget sur les systèmes CentOS et RedHat
yum:
name: wget
state: present
when: (ansible_distribution == 'CentOS' or ansible_distribution) == 'RedHat' and reponse_mysql == 'oui'
- file:
path: /etc/repo_mysql
state: directory
when: reponse_mysql == 'oui'
- name: Téléchargement dépôt mysql sur les systèmes CentOS et RedHat
get_url:
url: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
dest: /etc/repo_mysql/mysql-community-release-el7-5.noarch.rpm
when: (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat') and reponse_mysql == 'oui'
- name: Installation dépôt mysql sur les systèmes CentOS et RedHat
yum:
name: /etc/repo_mysql/mysql-community-release-el7-5.noarch.rpm
state: present
when: (ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat') and reponse_mysql == 'oui'
- name: Installation mysql sur tous les systèmes
yum:
name: mysql-server
state: present
when: reponse_mysql == 'oui'
- name: Creation BDD "vierge" sur tous les systèmes
mysql_db:
name: vierge
state: present
when: reponse_mysql == 'oui'
- name: Demarrage mysql sur les systèmes Debian et Ubuntu
service:
name: mysql
state: started
when: (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu') and reponse_mysql == 'oui'
- name: Demarrage mysql sur les systèmes CentOS et RedHat
service:
name: mysqld
state: started