Compare commits
2 Commits
master
...
14662a811a
| Author | SHA1 | Date | |
|---|---|---|---|
| 14662a811a | |||
| 68929bc91d |
20
Readme.md
20
Readme.md
@@ -10,14 +10,22 @@
|
|||||||
|
|
||||||
** Pratique **
|
** Pratique **
|
||||||
|
|
||||||
En examinant les différents fichiers présents dans ce dépôt, essayez de
|
Récupérer la solution de l'atelier handler
|
||||||
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.
|
Identifier dans le playbook et le fichier vhost.conf toutes les spécificités de RedHat (qui vont empécher le playbook de fonctionner)
|
||||||
|
|
||||||
|
Trouver la solution à cette problématique (exécution conditionnelle, variabilisation ...)
|
||||||
|
|
||||||
|
Implémenter la solution
|
||||||
|
|
||||||
|
Sur la debian, la configuration par défaut entre en conflit avec la notre:
|
||||||
|
|
||||||
|
Modifier le playbook pour que le fichier /etc/apache2/sites-enabled/000-default.conf soit supprimé UNIQUEMENT sur la debian, avec redémarrage du service apache si besoin
|
||||||
|
|
||||||
Ce playbook n'est pas complet. Déterminez les éléments manquants et corrigez.
|
|
||||||
|
|
||||||
** Validation:
|
** Validation:
|
||||||
|
|
||||||
le playbook s'exécute correctement sur la machine debian
|
```bash
|
||||||
|
curl debian1
|
||||||
|
<span style="text-align: center;background-color: #FD5401; font-size: 42px;">Hello World</span>
|
||||||
|
```
|
||||||
60
apache.yml
60
apache.yml
@@ -8,63 +8,55 @@
|
|||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: read OS var file
|
||||||
|
include_vars: "{{ ansible_os_family | lower }}.yml"
|
||||||
|
|
||||||
- name: install apache
|
- name: install apache
|
||||||
package:
|
package:
|
||||||
name: "{{ apache_package_name }}"
|
name: "{{ apache_package_name }}"
|
||||||
state: present
|
state: latest
|
||||||
|
|
||||||
- name: conf httpd
|
- name: conf httpd
|
||||||
template:
|
template:
|
||||||
src: vhost.conf
|
src: vhost.conf
|
||||||
dest: "{{ apache_config_dir}}/vhost.conf"
|
dest: "{{ apache_config_dir }}/vhost.conf"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
owner: root
|
owner: root
|
||||||
group: apache
|
group: "{{ apache_group }}"
|
||||||
notify: restart apache
|
notify: restart apache
|
||||||
|
|
||||||
|
- name: delete defaultconf on debian
|
||||||
|
file:
|
||||||
|
path: "{{ apache_config_dir }}/000-default.conf"
|
||||||
|
state: absent
|
||||||
|
notify: restart apache
|
||||||
|
when: ansible_os_family == 'Debian'
|
||||||
|
|
||||||
|
- name: call handlers, if needed
|
||||||
|
ansible.builtin.meta: flush_handlers
|
||||||
|
|
||||||
- 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
|
- name: open firewall port
|
||||||
file:
|
firewalld:
|
||||||
path: /etc/apache2/sites-enabled/000-default.conf
|
service: http
|
||||||
state: absent
|
permanent: yes
|
||||||
notify: restart apache
|
immediate: yes
|
||||||
|
state: enabled
|
||||||
- name: setup firewall
|
ignore_errors: yes
|
||||||
block:
|
when: ansible_os_family=='RedHat'
|
||||||
- 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
|
- name: create documentroot
|
||||||
file:
|
file:
|
||||||
name: /var/www/html/example.org/
|
name: /var/www/html/example.org
|
||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: copy index file
|
- name: create index file
|
||||||
template:
|
copy:
|
||||||
src: index.txt
|
src: index.txt
|
||||||
dest: /var/www/html/example.org/index.html
|
dest: /var/www/html/example.org/index.html
|
||||||
mode: 0644
|
mode: 0644
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#/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
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
#/home/formation/sib_10_premier_playbook/debian.yml
|
#/home/formation/sib_12_handlers/debian.yml
|
||||||
|
---
|
||||||
apache_service_name: apache2
|
apache_service_name: apache2
|
||||||
apache_package_name: apache2
|
apache_package_name: apache2
|
||||||
|
apache_user: www-data
|
||||||
|
apache_group: www-data
|
||||||
apache_config_dir: /etc/apache2/sites-enabled/
|
apache_config_dir: /etc/apache2/sites-enabled/
|
||||||
apache_log_dir: /var/log/apache2
|
apache_log_dir: /var/log/apache2/
|
||||||
|
|
||||||
|
|||||||
8
redhat.yml
Normal file
8
redhat.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#/home/formation/sib_12_handlers/redhat.yml
|
||||||
|
---
|
||||||
|
apache_service_name: httpd
|
||||||
|
apache_package_name: httpd
|
||||||
|
apache_user: apache
|
||||||
|
apache_group: apache
|
||||||
|
apache_config_dir: /etc/httpd/conf.d/
|
||||||
|
apache_log_dir: /var/log/httpd/
|
||||||
25
vhost.conf
25
vhost.conf
@@ -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>
|
|
||||||
Reference in New Issue
Block a user