Merge branch 'adaptationPlaybookExistantSolution' into solution
This commit is contained in:
33
Readme.md
33
Readme.md
@@ -3,15 +3,26 @@
|
|||||||
Plutôt que de conditionner chaque tâche en fonction de la distribution (ce qui sera pénible et difficile à maintenir), la solution consistant à inclure un fichier de variables propre à chaque OS cible est plus élégante.
|
Plutôt que de conditionner chaque tâche en fonction de la distribution (ce qui sera pénible et difficile à maintenir), la solution consistant à inclure un fichier de variables propre à chaque OS cible est plus élégante.
|
||||||
|
|
||||||
|
|
||||||
Autre cas d'utilisation des includes:
|
**Préparation**:
|
||||||
|
|
||||||
```yaml
|
** Pratique **
|
||||||
- name: ensure bootstrap role has been applied
|
|
||||||
include_role:
|
En examinant les différents fichiers présents dans ce dépôt, essayez de
|
||||||
name: bootstrap
|
déterminez de quelle manière ce playbook a été adapté pour fonctionner aussi
|
||||||
when: apply_bootstrap_role
|
bien sur une CentOS qu'une Debian.
|
||||||
- include: bash.yml
|
|
||||||
tags: bash
|
L'idée est de transformer en variables toutes les spécificités de chaque distribution (nom
|
||||||
- include: local_repo.yml
|
du paquet, du service, de l'utilisateur dédié au service, du répertoire de conf ...) et de définir ces variables dans des fichiers dont le nom correspond à la distribution cible.
|
||||||
when: ansible_distribution=='CentOS' and use_local_repo
|
|
||||||
```
|
Il suffit de faire ensuite un include de ces fichiers en construisant le nom du fichier autour de la variable "ansible_distribution"
|
||||||
|
|
||||||
|
L'exécution du block de tâches "firewalld", spécifique à CentOS est conditionné à cette distribution via la clause "when"
|
||||||
|
|
||||||
|
La tâche "conf httpd" ne fonctionnera pas sur Debian. Pourquoi ? Proposez une solution.
|
||||||
|
|
||||||
|
Le nom du groupe est différent, il faut en faire une variable
|
||||||
|
|
||||||
|
|
||||||
|
** Validation:
|
||||||
|
|
||||||
|
le playbook s'exécute correctement sur la machine debian
|
||||||
|
|||||||
63
apache.yml
63
apache.yml
@@ -1,9 +1,15 @@
|
|||||||
---
|
---
|
||||||
- name: install apache via ansible playbook
|
- name: install apache via ansible playbook
|
||||||
hosts: cibles
|
hosts: all
|
||||||
|
handlers:
|
||||||
|
- name: restart apache
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: restarted
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: import OS Specific variables
|
|
||||||
|
- name: import OS variables
|
||||||
include_vars: "{{ ansible_distribution | lower }}.yml"
|
include_vars: "{{ ansible_distribution | lower }}.yml"
|
||||||
|
|
||||||
- name: install apache
|
- name: install apache
|
||||||
@@ -11,8 +17,59 @@
|
|||||||
name: "{{ apache_package_name }}"
|
name: "{{ apache_package_name }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
|
- name: conf httpd
|
||||||
|
template:
|
||||||
|
src: vhost.conf
|
||||||
|
dest: "{{ apache_config_dir}}/vhost.conf"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: "{{ apache_group_name }}"
|
||||||
|
notify: restart apache
|
||||||
|
|
||||||
- name: activate apache
|
- name: activate apache
|
||||||
service:
|
service:
|
||||||
name: "{{ apache_service_name }}"
|
name: "{{ apache_service_name }}"
|
||||||
enabled: yes
|
enabled: yes
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
|
- name: remove default site conf
|
||||||
|
file:
|
||||||
|
path: /etc/apache2/sites-enabled/000-default.conf
|
||||||
|
state: absent
|
||||||
|
notify: restart apache
|
||||||
|
|
||||||
|
- name: setup firewall
|
||||||
|
block:
|
||||||
|
- name: install firewalld packages
|
||||||
|
yum:
|
||||||
|
name:
|
||||||
|
- python3-firewall
|
||||||
|
- firewalld
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: enable firewalld service
|
||||||
|
service:
|
||||||
|
name: firewalld
|
||||||
|
enabled: true
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: open firewall port
|
||||||
|
firewalld:
|
||||||
|
service: http
|
||||||
|
permanent: yes
|
||||||
|
immediate: yes
|
||||||
|
state: enabled
|
||||||
|
ignore_errors: true
|
||||||
|
when: ansible_distribution == 'CentOS'
|
||||||
|
|
||||||
|
|
||||||
|
- name: create documentroot
|
||||||
|
file:
|
||||||
|
name: /var/www/html/example.org/
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: copy index file
|
||||||
|
template:
|
||||||
|
src: index.txt
|
||||||
|
dest: /var/www/html/example.org/index.html
|
||||||
|
mode: 0644
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
|
#/home/formation/sib_10_premier_playbook/centos.yml
|
||||||
|
apache_service_name: httpd
|
||||||
apache_package_name: httpd
|
apache_package_name: httpd
|
||||||
apache_service_name: httpd
|
apache_config_dir: /etc/httpd/conf.d
|
||||||
|
apache_log_dir: /var/log/httpd
|
||||||
|
apache_group_name: apache
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
|
#/home/formation/sib_10_premier_playbook/debian.yml
|
||||||
|
apache_service_name: apache2
|
||||||
apache_package_name: apache2
|
apache_package_name: apache2
|
||||||
apache_service_name: apache2
|
apache_config_dir: /etc/apache2/sites-enabled/
|
||||||
|
apache_log_dir: /var/log/apache2
|
||||||
|
apache_group_name: www-data
|
||||||
|
|||||||
25
vhost.conf
Normal file
25
vhost.conf
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#/home/formation/sib_10_premier_playbook/vhost.conf
|
||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName example.org
|
||||||
|
ServerAlias www.example.org
|
||||||
|
ServerAlias {{ inventory_hostname }}
|
||||||
|
DocumentRoot /var/www/html/example.org
|
||||||
|
CustomLog {{ apache_log_dir }}/example.org_access.log combined
|
||||||
|
ErrorLog {{ apache_log_dir }}/example.org_error.log
|
||||||
|
<Directory />
|
||||||
|
Options none
|
||||||
|
Allowoverride none
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory /var/www/html/example.org>
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
<Directory /var/www/html/example.org/Private>
|
||||||
|
Options indexes
|
||||||
|
AuthName "stop"
|
||||||
|
AuthType Basic
|
||||||
|
AuthUserFile /etc/{{ apache_service_name }}/passwd
|
||||||
|
require valid-user
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
Reference in New Issue
Block a user