Compare commits
2 Commits
solution_a
...
b8297efac6
| Author | SHA1 | Date | |
|---|---|---|---|
| b8297efac6 | |||
| 250b199fea |
38
Readme.md
38
Readme.md
@@ -1,31 +1,17 @@
|
||||
## Includes et import
|
||||
# Solution (proposition)
|
||||
|
||||
**Tâche**: écrire des playbooks modulaires
|
||||
|
||||
**Condition**: selon besoin
|
||||
|
||||
**Norme**: includes et import
|
||||
|
||||
**Préparation**:
|
||||
|
||||
** Pratique **
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||
|
||||
** Validation:
|
||||
Autre cas d'utilisation des includes:
|
||||
|
||||
```bash
|
||||
curl debian1
|
||||
<span style="text-align: center;background-color: #FD5401; font-size: 42px;">Hello World</span>
|
||||
```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
|
||||
```
|
||||
54
apache.yml
54
apache.yml
@@ -1,62 +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: read OS var file
|
||||
include_vars: "{{ ansible_os_family | lower }}.yml"
|
||||
- name: import OS Specific variables
|
||||
include_vars: "{{ ansible_distribution | lower }}.yml"
|
||||
|
||||
- name: install apache
|
||||
package:
|
||||
name: "{{ apache_package_name }}"
|
||||
state: latest
|
||||
|
||||
- name: conf httpd
|
||||
template:
|
||||
src: vhost.conf
|
||||
dest: "{{ apache_config_dir }}/vhost.conf"
|
||||
mode: 0640
|
||||
owner: root
|
||||
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
|
||||
state: present
|
||||
|
||||
- name: activate apache
|
||||
service:
|
||||
name: "{{ apache_service_name }}"
|
||||
enabled: yes
|
||||
state: started
|
||||
|
||||
- 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
|
||||
state: directory
|
||||
|
||||
- name: create index file
|
||||
copy:
|
||||
src: index.txt
|
||||
dest: /var/www/html/example.org/index.html
|
||||
mode: 0644
|
||||
state: started
|
||||
2
centos.yml
Normal file
2
centos.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
apache_package_name: httpd
|
||||
apache_service_name: httpd
|
||||
@@ -1,9 +1,2 @@
|
||||
#/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_service_name: apache2
|
||||
@@ -1,8 +0,0 @@
|
||||
#/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