atelier variable abr - solution
This commit is contained in:
12
Readme.md
12
Readme.md
@@ -20,15 +20,17 @@ cd sib_12_handlers
|
|||||||
|
|
||||||
### Pratique:
|
### Pratique:
|
||||||
|
|
||||||
Ce playbook présente quelques problèmes à identifier.
|
Ce playbook présente beaucoup de redondance (nom de répertoire, nom du site ...) ce qui ne facilite pas sa maintenance.
|
||||||
|
|
||||||
Remplacer ces éléments répétés dans les différents éléments par des variables judicieusement nommées.
|
J'ai choisie d'utiliser les variables:
|
||||||
|
|
||||||
Tenter de définir la valeur de ces variables. On s'intéressera notamment à la problématique: comment définir la variable "nom du site" pour que l'on puisse héberger un site différent par machine ?
|
- apache_documentroot
|
||||||
|
- apache_site_name
|
||||||
|
|
||||||
|
J'ai défini ces variables dans la section _vars_ du playbook. C'est loin d'être idéal ...
|
||||||
|
|
||||||
### Performance
|
### Performance
|
||||||
|
|
||||||
Il est désormais facile d'adapter le playbook pour qu'il traite un autre site que www.orsys.fr
|
Il est désormais facile d'adapter le playbook pour qu'il traite un autre site que www.orsys.fr
|
||||||
|
|
||||||
Solution: voir branche "solution"
|
Il suffit de changer la valeur de la variable.
|
||||||
|
|
||||||
|
|||||||
51
apache.yml
Normal file
51
apache.yml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
- name: install apache via ansible playbook
|
||||||
|
hosts: cibles
|
||||||
|
vars:
|
||||||
|
apache_site_name: "orsys.fr"
|
||||||
|
apache_documentroot: "/srv/www/{{ apache_site_name }}"
|
||||||
|
handlers:
|
||||||
|
- name: restart apache
|
||||||
|
service:
|
||||||
|
name: httpd
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- name: install apache
|
||||||
|
yum:
|
||||||
|
name: httpd
|
||||||
|
state: latest
|
||||||
|
|
||||||
|
- name: conf httpd
|
||||||
|
template:
|
||||||
|
src: vhost.conf
|
||||||
|
dest: /etc/httpd/conf.d/vhost.conf
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: apache
|
||||||
|
notify: restart apache
|
||||||
|
|
||||||
|
- name: activate apache
|
||||||
|
service:
|
||||||
|
name: httpd
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
|
||||||
|
- name: open firewall port
|
||||||
|
firewalld:
|
||||||
|
service: http
|
||||||
|
permanent: yes
|
||||||
|
immediate: yes
|
||||||
|
state: enabled
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: create documentroot
|
||||||
|
file:
|
||||||
|
name: "{{ apache_documentroot }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: create index file
|
||||||
|
copy:
|
||||||
|
src: index.txt
|
||||||
|
dest: "{{ apache_documentroot }}/index.html"
|
||||||
|
mode: 0644
|
||||||
1
index.txt
Normal file
1
index.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<span style="text-align: center;background-color: #FD5401; font-size: 42px;">Hello World</span>
|
||||||
16
vhost.conf
Normal file
16
vhost.conf
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName {{ apache_site_name }}
|
||||||
|
ServerAlias www.{{ apache_site_name }}
|
||||||
|
DocumentRoot {{ apache_documentroot }}/
|
||||||
|
CustomLog /var/log/httpd/{{ apache_site_name }}_access.log combined
|
||||||
|
ErrorLog /var/log/httpd/{{ apache_site_name }}_error.log
|
||||||
|
<Directory />
|
||||||
|
Options none
|
||||||
|
Allowoverride none
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory {{ apache_documentroot }}>
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
Reference in New Issue
Block a user