solution
This commit is contained in:
12
Readme
12
Readme
@@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
Tâche: Utiliser des variables
|
|
||||||
Condition: très souvent ;)
|
|
||||||
Norme: éditeur de texte, modules template, variable d'inventaire
|
|
||||||
|
|
||||||
Objectif: Toujours avec des variables, faire en sorte qu'une machine puisse héberger *plusieurs* vhost
|
|
||||||
|
|
||||||
Prérequis:
|
|
||||||
* On peut se baser sur l'exercice précédent.
|
|
||||||
|
|
||||||
Validation: le playbook s'exécute correctement sur nos cibles.
|
|
||||||
Chaque cible héberge plusieurs sites différents.
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
---
|
---
|
||||||
- name: install apache via ansible playbook
|
- name: install apache via ansible playbook
|
||||||
hosts: test
|
hosts: cibles
|
||||||
user: ansible
|
|
||||||
become: true
|
|
||||||
roles:
|
roles:
|
||||||
- myapache2
|
- apache
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Role Name
|
|||||||
|
|
||||||
Rôle de deploiement apache sur une centos.
|
Rôle de deploiement apache sur une centos.
|
||||||
|
|
||||||
more than 1 vhost per host
|
1 seul vhost
|
||||||
|
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
@@ -14,15 +14,11 @@ Role Variables
|
|||||||
--------------
|
--------------
|
||||||
|
|
||||||
http_port: 80
|
http_port: 80
|
||||||
|
servername: orsys.fr
|
||||||
Hosts variables
|
serveralias: "www.{{ servername }}"
|
||||||
--------------
|
documentroot: /var/www/html/orsys.fr
|
||||||
apache_vhosts:
|
accesslog: /var/log/httpd/access_orsys.fr_log
|
||||||
- servername: orsys.fr
|
errorlog: /var/log/httpd/error_orsys.fr_log
|
||||||
serveralias: "www.{{ servername }}"
|
|
||||||
documentroot: /var/www/html/orsys.fr
|
|
||||||
accesslog: /var/log/httpd/access_orsys.fr_log
|
|
||||||
errorlog: /var/log/httpd/error_orsys.fr_log
|
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
------------
|
------------
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
# handlers file for myapache
|
# handlers file for myapache
|
||||||
- name: reload httpd
|
- name: reload httpd
|
||||||
service:
|
service:
|
||||||
name: httpd
|
name: "{{ apache_service_name }}"
|
||||||
state: reloaded
|
state: reloaded
|
||||||
|
|
||||||
- name: reload firewalld
|
- name: reload firewalld
|
||||||
@@ -1,24 +1,34 @@
|
|||||||
---
|
---
|
||||||
# tasks file for myapache
|
# tasks file for myapache
|
||||||
- name: install apache
|
#
|
||||||
yum:
|
- name: include distribution specific variables
|
||||||
name: httpd
|
include_vars: "{{ ansible_distribution|lower }}.yml"
|
||||||
|
|
||||||
|
- name: install apache almost anywhere
|
||||||
|
tags: httpd
|
||||||
|
package:
|
||||||
|
name: "{{ apache_package_name}}"
|
||||||
state: latest
|
state: latest
|
||||||
|
|
||||||
|
|
||||||
- name: conf httpd
|
- name: conf httpd
|
||||||
|
tags: httpd
|
||||||
notify: reload httpd
|
notify: reload httpd
|
||||||
template:
|
template:
|
||||||
src: vhost.conf.jj
|
src: vhost.conf.jj
|
||||||
dest: /etc/httpd/conf.d/vhost.conf
|
dest: "{{ apache_conf_dir}}/vhost.conf"
|
||||||
mode: 0640
|
mode: 0640
|
||||||
owner: root
|
owner: root
|
||||||
group: apache
|
group: apache
|
||||||
|
|
||||||
- name: activate apache
|
- name: activate apache
|
||||||
|
tags: httpd
|
||||||
service:
|
service:
|
||||||
name: httpd
|
name: "{{ apache_service_name }}"
|
||||||
enabled: yes
|
enabled: yes
|
||||||
|
|
||||||
- name: open firewall port
|
- name: open firewall port
|
||||||
|
tags: httpd
|
||||||
firewalld:
|
firewalld:
|
||||||
service: http
|
service: http
|
||||||
permanent: yes
|
permanent: yes
|
||||||
@@ -26,8 +36,10 @@
|
|||||||
state: enabled
|
state: enabled
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
notify: reload firewalld
|
notify: reload firewalld
|
||||||
|
when: ansible_distribution=="CentOS" or "RedHat"
|
||||||
|
|
||||||
- name: create documentroot
|
- name: create documentroot
|
||||||
|
tags: httpd
|
||||||
file:
|
file:
|
||||||
name: "{{ item.documentroot }}"
|
name: "{{ item.documentroot }}"
|
||||||
state: directory
|
state: directory
|
||||||
@@ -35,9 +47,10 @@
|
|||||||
- "{{ apache_vhosts }}"
|
- "{{ apache_vhosts }}"
|
||||||
|
|
||||||
- name: create index file
|
- name: create index file
|
||||||
|
tags: httpd
|
||||||
copy:
|
copy:
|
||||||
src: index.html
|
src: index.html
|
||||||
dest: "{{ item.documentroot }}/index.html"
|
dest: "{{ item.documentroot }}/index.html"
|
||||||
mode: 0644
|
mode: 0644
|
||||||
with_items:
|
with_items:
|
||||||
- "{{ apache_vhosts }}"
|
- "{{ apache_vhosts }}"
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
{% for vhost in apache_vhosts %}
|
{% for vhost in apache_vhosts %}
|
||||||
<VirtualHost *:{{ http_port }}>
|
<VirtualHost *:{{ http_port }}>
|
||||||
ServerName {{ vhost.servername }}
|
ServerName {{ vhost.servername }}
|
||||||
ServerAlias {{ vhost.serveralias }}
|
{% for alias in vhost.serveralias %}
|
||||||
|
ServerAlias {{ alias }}
|
||||||
|
{% endfor %}
|
||||||
DocumentRoot {{ vhost.documentroot }}
|
DocumentRoot {{ vhost.documentroot }}
|
||||||
CustomLog {{ vhost.accesslog }} combined
|
CustomLog {{ vhost.accesslog }} combined
|
||||||
ErrorLog {{ vhost.errorlog }}
|
ErrorLog {{ vhost.errorlog }}
|
||||||
@@ -11,8 +13,9 @@
|
|||||||
Require all denied
|
Require all denied
|
||||||
</Directory>
|
</Directory>
|
||||||
|
|
||||||
<Directory {{ vhost.documentroot }}>
|
<Directory {{ vhost.documentroot }}>
|
||||||
Require all granted
|
Options {{ vhost.documentrootoptions|default( "none" ) }}
|
||||||
|
Require all granted
|
||||||
</Directory>
|
</Directory>
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
3
apache/vars/centos.yml
Normal file
3
apache/vars/centos.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
apache_package_name: httpd
|
||||||
|
apache_service_name: httpd
|
||||||
|
apache_conf_dir: /etc/httpd/conf.d
|
||||||
3
apache/vars/debian.yml
Normal file
3
apache/vars/debian.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
apache_package_name: apache2
|
||||||
|
apache_service_name: apache2
|
||||||
|
apache_conf_dir: /etc/apache2/sites-enabled/
|
||||||
Reference in New Issue
Block a user