Compare commits

3 Commits

Author SHA1 Message Date
47b37fbcc8 typo 2022-04-26 09:40:38 +02:00
1456280ca8 variante on etudie et adapte un playbook existant 2022-04-26 09:34:53 +02:00
e37afec5a6 foo 2021-03-16 22:14:53 +01:00
6 changed files with 109 additions and 19 deletions

View File

@@ -1,17 +1,23 @@
# Solution (proposition) ## Includes et import
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. **Tâche**: écrire des playbooks modulaires
**Condition**: selon besoin
Autre cas d'utilisation des includes: **Norme**: includes et import
```yaml **Préparation**:
- name: ensure bootstrap role has been applied
include_role: ** Pratique **
name: bootstrap
when: apply_bootstrap_role En examinant les différents fichiers présents dans ce dépôt, essayez de
- include: bash.yml déterminez de quelle manière ce playbook a été adapté pour fonctionner aussi
tags: bash bien sur une CentOS qu'une Debian.
- include: local_repo.yml
when: ansible_distribution=='CentOS' and use_local_repo 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

View File

@@ -1,18 +1,70 @@
--- ---
- name: install apache via ansible playbook - name: install apache via ansible playbook
hosts: cibles hosts: all
handlers:
- name: restart apache
service:
name: "{{ apache_service_name }}"
state: restarted
tasks: tasks:
- name: import OS Specific variables
include_vars: "{{ ansible_distribution | lower }}.yml"
- name: install apache - name: install apache
package: package:
name: "{{ apache_package_name }}" name: "{{ apache_package_name }}"
state: present 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 - 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
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: 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

View File

@@ -1,2 +1,5 @@
apache_package_name: httpd #/home/formation/sib_10_premier_playbook/centos.yml
apache_service_name: httpd apache_service_name: httpd
apache_package_name: httpd
apache_config_dir: /etc/httpd/conf.d
apache_log_dir: /var/log/httpd

View File

@@ -1,2 +1,5 @@
apache_package_name: apache2 #/home/formation/sib_10_premier_playbook/debian.yml
apache_service_name: apache2 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>