Compare commits
5 Commits
b8297efac6
...
solution_a
| Author | SHA1 | Date | |
|---|---|---|---|
| 14662a811a | |||
| 68929bc91d | |||
| 47b37fbcc8 | |||
| 1456280ca8 | |||
| e37afec5a6 |
22
Readme.md
22
Readme.md
@@ -10,14 +10,22 @@
|
|||||||
|
|
||||||
** Pratique **
|
** Pratique **
|
||||||
|
|
||||||
Adapter le playbook apache.yml pour qu'il fonctionne sur la machine _debian_:
|
Récupérer la solution de l'atelier handler
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
** Validation:
|
** Validation:
|
||||||
|
|
||||||
le playbook s'exécute correctement sur la machine debian
|
```bash
|
||||||
|
curl debian1
|
||||||
Chaque cible héberge plusieurs sites différents.
|
<span style="text-align: center;background-color: #FD5401; font-size: 42px;">Hello World</span>
|
||||||
Proposition de solution: voir la branche "solution"
|
```
|
||||||
44
apache.yml
44
apache.yml
@@ -1,24 +1,43 @@
|
|||||||
---
|
---
|
||||||
- name: install apache via ansible playbook
|
- name: install apache via ansible playbook
|
||||||
hosts: centos
|
hosts: all
|
||||||
|
handlers:
|
||||||
|
- name: restart apache
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: restarted
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: read OS var file
|
||||||
|
include_vars: "{{ ansible_os_family | lower }}.yml"
|
||||||
|
|
||||||
- name: install apache
|
- name: install apache
|
||||||
yum:
|
package:
|
||||||
name: httpd
|
name: "{{ apache_package_name }}"
|
||||||
state: present
|
state: latest
|
||||||
|
|
||||||
- name: conf httpd
|
- name: conf httpd
|
||||||
template:
|
template:
|
||||||
src: vhost.conf
|
src: vhost.conf
|
||||||
dest: /etc/httpd/conf.d/vhost.conf
|
dest: "{{ apache_config_dir }}/vhost.conf"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
owner: root
|
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
|
- name: activate apache
|
||||||
service:
|
service:
|
||||||
name: httpd
|
name: "{{ apache_service_name }}"
|
||||||
enabled: yes
|
enabled: yes
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
@@ -28,15 +47,16 @@
|
|||||||
permanent: yes
|
permanent: yes
|
||||||
immediate: yes
|
immediate: yes
|
||||||
state: enabled
|
state: enabled
|
||||||
ignore_errors: true
|
ignore_errors: yes
|
||||||
|
when: ansible_os_family=='RedHat'
|
||||||
|
|
||||||
- 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
|
||||||
|
|||||||
9
debian.yml
Normal file
9
debian.yml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#/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/
|
||||||
|
|
||||||
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/
|
||||||
Reference in New Issue
Block a user