2 Commits

Author SHA1 Message Date
14662a811a solution abr 2023-09-21 09:48:05 +02:00
68929bc91d tp abr 2023-09-21 09:47:20 +02:00
7 changed files with 55 additions and 74 deletions

View File

@@ -10,14 +10,22 @@
** 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.
Récupérer la solution de l'atelier handler
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:
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>
```

View File

@@ -8,63 +8,55 @@
state: restarted
tasks:
- name: read OS var file
include_vars: "{{ ansible_os_family | lower }}.yml"
- name: install apache
package:
name: "{{ apache_package_name }}"
state: present
state: latest
- name: conf httpd
template:
src: vhost.conf
dest: "{{ apache_config_dir}}/vhost.conf"
dest: "{{ apache_config_dir }}/vhost.conf"
mode: 0640
owner: root
group: apache
group: "{{ apache_group }}"
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
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: open firewall port
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
ignore_errors: yes
when: ansible_os_family=='RedHat'
- name: create documentroot
file:
name: /var/www/html/example.org/
name: /var/www/html/example.org
state: directory
- name: copy index file
template:
- name: create index file
copy:
src: index.txt
dest: /var/www/html/example.org/index.html
mode: 0644
mode: 0644

View File

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

View File

@@ -1,5 +1,9 @@
#/home/formation/sib_10_premier_playbook/debian.yml
#/home/formation/sib_12_handlers/debian.yml
---
apache_service_name: apache2
apache_package_name: apache2
apache_user: www-data
apache_group: www-data
apache_config_dir: /etc/apache2/sites-enabled/
apache_log_dir: /var/log/apache2
apache_log_dir: /var/log/apache2/

View File

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

8
redhat.yml Normal file
View 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/

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>