variante on etudie et adapte un playbook existant

This commit is contained in:
2022-04-26 09:34:53 +02:00
parent e37afec5a6
commit 1456280ca8
6 changed files with 105 additions and 12 deletions

View File

@@ -10,14 +10,14 @@
** Pratique **
Adapter le playbook apache.yml pour qu'il fonctionne sur la machine _debian_:
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.
1. identifiez les différences entre OS (nom des packages, des services, répertoires différents, ...)
2. essayez de trouver une solution permettant de gérer ses différences.
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
Chaque cible héberge plusieurs sites différents.
Proposition de solution: voir la branche "solution"
le playbook s'exécute correctement sur la machine debian

View File

@@ -1,15 +1,72 @@
---
- name: install apache via ansible playbook
hosts: centos
hosts: all
handlers:
- name: restart apache
service:
name: "{{ apache_service_name }}"
state: restarted
tasks:
- name: install apache
yum:
name: httpd
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: httpd
name: "{{ apache_service_name }}"
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

5
centos.yml Normal file
View File

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

5
debian.yml Normal file
View File

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

1
index.txt Normal file
View File

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

25
vhost.conf Normal file
View 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>