Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 920af07166 | |||
| 3bc092ada5 | |||
| db9f049e68 | |||
| 6d279c75bb |
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
|
||||
hosts: test
|
||||
user: ansible
|
||||
become: true
|
||||
hosts: all
|
||||
roles:
|
||||
- myapache2
|
||||
- apache
|
||||
|
||||
@@ -3,7 +3,7 @@ Role Name
|
||||
|
||||
Rôle de deploiement apache sur une centos.
|
||||
|
||||
more than 1 vhost per host
|
||||
1 seul vhost
|
||||
|
||||
Requirements
|
||||
------------
|
||||
@@ -14,15 +14,11 @@ Role Variables
|
||||
--------------
|
||||
|
||||
http_port: 80
|
||||
|
||||
Hosts variables
|
||||
--------------
|
||||
apache_vhosts:
|
||||
- servername: orsys.fr
|
||||
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
|
||||
servername: orsys.fr
|
||||
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
|
||||
------------
|
||||
@@ -2,7 +2,7 @@
|
||||
# handlers file for myapache
|
||||
- name: reload httpd
|
||||
service:
|
||||
name: httpd
|
||||
name: "{{ apache_service_name }}"
|
||||
state: reloaded
|
||||
|
||||
- name: reload firewalld
|
||||
60
apache/tasks/main.yml
Normal file
60
apache/tasks/main.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
# tasks file for myapache
|
||||
#
|
||||
- name: include distribution specific variables
|
||||
include_vars: "{{ ansible_os_family|lower }}.yml"
|
||||
|
||||
- name: install apache almost anywhere
|
||||
tags: httpd
|
||||
package:
|
||||
name: "{{ apache_package_name}}"
|
||||
state: latest
|
||||
|
||||
- name: conf httpd
|
||||
tags: httpd
|
||||
notify: reload httpd
|
||||
template:
|
||||
src: vhost.conf.jj
|
||||
dest: "{{ apache_conf_dir}}/vhost.conf"
|
||||
mode: 0640
|
||||
owner: root
|
||||
group: "{{ apache_group_name }}"
|
||||
|
||||
- name: activate apache
|
||||
tags: httpd
|
||||
service:
|
||||
name: "{{ apache_service_name }}"
|
||||
enabled: yes
|
||||
|
||||
- name: open firewall port
|
||||
tags: httpd
|
||||
firewalld:
|
||||
service: http
|
||||
permanent: yes
|
||||
immediate: yes
|
||||
state: enabled
|
||||
ignore_errors: yes
|
||||
notify: reload firewalld
|
||||
when: ansible_os_family=="RedHat"
|
||||
|
||||
- name: create documentroot
|
||||
tags: httpd
|
||||
file:
|
||||
name: "{{ item.documentroot }}"
|
||||
state: directory
|
||||
loop: "{{ apache_vhosts }}"
|
||||
|
||||
- name: create documentroot/Private
|
||||
tags: httpd
|
||||
file:
|
||||
name: "{{ item.documentroot }}/Private"
|
||||
state: directory
|
||||
loop: "{{ apache_vhosts }}"
|
||||
|
||||
- name: create index file
|
||||
tags: httpd
|
||||
copy:
|
||||
src: index.html
|
||||
dest: "{{ item.documentroot }}/index.html"
|
||||
mode: 0644
|
||||
loop: "{{ apache_vhosts }}"
|
||||
@@ -1,7 +1,9 @@
|
||||
{% for vhost in apache_vhosts %}
|
||||
<VirtualHost *:{{ http_port }}>
|
||||
ServerName {{ vhost.servername }}
|
||||
ServerAlias {{ vhost.serveralias }}
|
||||
{% for alias in vhost.serveralias %}
|
||||
ServerAlias {{ alias }}
|
||||
{% endfor %}
|
||||
DocumentRoot {{ vhost.documentroot }}
|
||||
CustomLog {{ vhost.accesslog }} combined
|
||||
ErrorLog {{ vhost.errorlog }}
|
||||
@@ -11,8 +13,9 @@
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<Directory {{ vhost.documentroot }}>
|
||||
Require all granted
|
||||
<Directory {{ vhost.documentroot }}>
|
||||
Options {{ vhost.documentrootoptions|default( "none" ) }}
|
||||
Require all granted
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
{% endfor %}
|
||||
4
apache/vars/debian.yml
Normal file
4
apache/vars/debian.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
apache_package_name: apache2
|
||||
apache_group_name: www-data
|
||||
apache_service_name: apache2
|
||||
apache_conf_dir: /etc/apache2/sites-enabled/
|
||||
4
apache/vars/redhat.yml
Normal file
4
apache/vars/redhat.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
apache_package_name: httpd
|
||||
apache_group_name: apache
|
||||
apache_service_name: httpd
|
||||
apache_conf_dir: /etc/httpd/conf.d
|
||||
@@ -1,11 +1,11 @@
|
||||
apache_vhosts:
|
||||
- servername: orsys.fr
|
||||
serveralias: www.orsys.fr
|
||||
serveralias: [ www.orsys.fr ]
|
||||
documentroot: /var/www/html/orsys.fr
|
||||
accesslog: /var/log/httpd/access_orsys.fr_log
|
||||
errorlog: /var/log/httpd/error_orsys.fr_log
|
||||
- servername: thomas.fr
|
||||
serveralias: www.thomas.fr
|
||||
serveralias: [ www.thomas.fr, thomas.org ]
|
||||
documentroot: /var/www/html/thomas.fr
|
||||
accesslog: /var/log/httpd/access_thomas.fr_log
|
||||
errorlog: /var/log/httpd/error_thomas.fr_log
|
||||
@@ -1,11 +0,0 @@
|
||||
apache_vhosts:
|
||||
- servername: foobar.com
|
||||
serveralias: www.foobar.com
|
||||
documentroot: /var/www/html/foobar.com
|
||||
accesslog: /var/log/httpd/access_foobar.com_log
|
||||
errorlog: /var/log/httpd/error_foobar.com_log
|
||||
- servername: AllYourBaseAreBelong2.us
|
||||
serveralias: www.AllYourBaseAreBelong2.us
|
||||
documentroot: /var/www/html/AllYourBaseAreBelong2.us
|
||||
accesslog: /var/log/httpd/access_AllYourBaseAreBelong2.us_log
|
||||
errorlog: /var/log/httpd/error_AllYourBaseAreBelong2.us_log
|
||||
12
host_vars/debian1.formation.opendoor.fr
Normal file
12
host_vars/debian1.formation.opendoor.fr
Normal file
@@ -0,0 +1,12 @@
|
||||
apache_vhosts:
|
||||
- servername: tartempion.fr
|
||||
serveralias: [www.tartempion.fr ]
|
||||
documentroot: /var/www/html/tartempion.fr
|
||||
accesslog: /var/log/apache2/access_tartempion.fr_log
|
||||
errorlog: /var/log/apache2/error_tartempion.fr_log
|
||||
- servername: delphine.fr
|
||||
serveralias: [ www.delphine.fr ]
|
||||
documentroot: /var/www/html/delphine.fr
|
||||
accesslog: /var/log/apache2/access_delphine.fr_log
|
||||
errorlog: /var/log/apache2/error_delphine.fr_log
|
||||
|
||||
2
inventory
Normal file
2
inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
centos1.formation.opendoor.fr
|
||||
debian1.formation.opendoor.fr
|
||||
@@ -1,43 +0,0 @@
|
||||
---
|
||||
# tasks file for myapache
|
||||
- name: install apache
|
||||
yum:
|
||||
name: httpd
|
||||
state: latest
|
||||
- name: conf httpd
|
||||
notify: reload httpd
|
||||
template:
|
||||
src: vhost.conf.jj
|
||||
dest: /etc/httpd/conf.d/vhost.conf
|
||||
mode: 0640
|
||||
owner: root
|
||||
group: apache
|
||||
|
||||
- name: activate apache
|
||||
service:
|
||||
name: httpd
|
||||
enabled: yes
|
||||
|
||||
- name: open firewall port
|
||||
firewalld:
|
||||
service: http
|
||||
permanent: yes
|
||||
immediate: yes
|
||||
state: enabled
|
||||
ignore_errors: yes
|
||||
notify: reload firewalld
|
||||
|
||||
- name: create documentroot
|
||||
file:
|
||||
name: "{{ item.documentroot }}"
|
||||
state: directory
|
||||
with_items:
|
||||
- "{{ apache_vhosts }}"
|
||||
|
||||
- name: create index file
|
||||
copy:
|
||||
src: index.html
|
||||
dest: "{{ item.documentroot }}/index.html"
|
||||
mode: 0644
|
||||
with_items:
|
||||
- "{{ apache_vhosts }}"
|
||||
Reference in New Issue
Block a user