Compare commits

2 Commits

Author SHA1 Message Date
b8297efac6 ajout readme 2021-05-06 16:59:16 +02:00
250b199fea solution 2021-03-16 22:14:17 +01:00
6 changed files with 19 additions and 109 deletions

View File

@@ -1,23 +1,17 @@
## Includes et import
# Solution (proposition)
**Tâche**: écrire des playbooks modulaires
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.
**Condition**: selon besoin
**Norme**: includes et import
Autre cas d'utilisation des includes:
**Préparation**:
** Pratique **
En examinant les différents fichiers présents dans ce dépôt, essayez de
déterminez de quelle manière ce playbook a été adapté pour fonctionner aussi
bien sur une CentOS qu'une Debian.
La tâche "conf httpd" ne fonctionnera pas sur Debian. Pourquoi ? Proposez une solution.
Ce playbook n'est pas complet. Déterminez les éléments manquants et corrigez.
** Validation:
le playbook s'exécute correctement sur la machine debian
```yaml
- name: ensure bootstrap role has been applied
include_role:
name: bootstrap
when: apply_bootstrap_role
- include: bash.yml
tags: bash
- include: local_repo.yml
when: ansible_distribution=='CentOS' and use_local_repo
```

View File

@@ -1,70 +1,18 @@
---
- name: install apache via ansible playbook
hosts: all
handlers:
- name: restart apache
service:
name: "{{ apache_service_name }}"
state: restarted
hosts: cibles
tasks:
- name: import OS Specific variables
include_vars: "{{ ansible_distribution | lower }}.yml"
- name: install apache
package:
name: "{{ apache_package_name }}"
state: present
- name: conf httpd
template:
src: vhost.conf
dest: "{{ apache_config_dir}}/vhost.conf"
mode: 0640
owner: root
group: apache
notify: restart apache
- name: activate apache
service:
name: "{{ apache_service_name }}"
enabled: yes
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
- 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

View File

@@ -1,5 +1,2 @@
#/home/formation/sib_10_premier_playbook/centos.yml
apache_service_name: httpd
apache_package_name: httpd
apache_config_dir: /etc/httpd/conf.d
apache_log_dir: /var/log/httpd
apache_service_name: httpd

View File

@@ -1,5 +1,2 @@
#/home/formation/sib_10_premier_playbook/debian.yml
apache_service_name: apache2
apache_package_name: apache2
apache_config_dir: /etc/apache2/sites-enabled/
apache_log_dir: /var/log/apache2
apache_service_name: apache2

View File

@@ -1 +0,0 @@
<h1>hello World</h1>

View File

@@ -1,25 +0,0 @@
#/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>