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.
|
|
||||||
16
Readme.md
Normal file
16
Readme.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Variables complexes
|
||||||
|
|
||||||
|
**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:
|
||||||
|
|
||||||
|
Validation: le playbook s'exécute correctement sur nos cibles.
|
||||||
|
Chaque cible héberge plusieurs sites différents.
|
||||||
|
|
||||||
|
Solution: voir branche "solution"
|
||||||
38
ansible_apache_formation/README.md
Normal file
38
ansible_apache_formation/README.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
apache_formation
|
||||||
|
|
||||||
|
NOT FOR PRODUCTION USE
|
||||||
|
|
||||||
|
This role has been designed for training purpose
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
---
|
||||||
|
- hosts: test
|
||||||
|
roles:
|
||||||
|
- apache_formation
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Thomas Constans <thomas@opendoor.fr>
|
||||||
1
ansible_apache_formation/defaults/main.yml
Normal file
1
ansible_apache_formation/defaults/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
4
ansible_apache_formation/handlers/main.yml
Normal file
4
ansible_apache_formation/handlers/main.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
- name: reload httpd
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: reloaded
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
galaxy_info:
|
galaxy_info:
|
||||||
author: your name
|
role_name: apache_formation
|
||||||
description: your description
|
author: Thomas Constans <thomas@opendoor.fr>
|
||||||
company: your company (optional)
|
description: Simple apache role set up for training purpose
|
||||||
|
company: www.opendoor.fr
|
||||||
|
|
||||||
# If the issue tracker for your role is not on github, uncomment the
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
# next line and provide a value
|
# next line and provide a value
|
||||||
@@ -14,7 +15,7 @@ galaxy_info:
|
|||||||
# - GPLv3
|
# - GPLv3
|
||||||
# - Apache
|
# - Apache
|
||||||
# - CC-BY
|
# - CC-BY
|
||||||
license: license (GPLv2, CC-BY, etc)
|
license: GPLv2
|
||||||
|
|
||||||
min_ansible_version: 1.2
|
min_ansible_version: 1.2
|
||||||
|
|
||||||
@@ -32,19 +33,12 @@ galaxy_info:
|
|||||||
#
|
#
|
||||||
# platforms is a list of platforms, and each platform has a name and a list of versions.
|
# platforms is a list of platforms, and each platform has a name and a list of versions.
|
||||||
#
|
#
|
||||||
# platforms:
|
platforms:
|
||||||
# - name: Fedora
|
- name: EL
|
||||||
# versions:
|
versions:
|
||||||
# - all
|
- 7
|
||||||
# - 25
|
|
||||||
# - name: SomePlatform
|
|
||||||
# versions:
|
|
||||||
# - all
|
|
||||||
# - 1.0
|
|
||||||
# - 7
|
|
||||||
# - 99.99
|
|
||||||
|
|
||||||
galaxy_tags: []
|
galaxy_tags: [apache,training]
|
||||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||||
# remove the '[]' above, if you add tags to this list.
|
# remove the '[]' above, if you add tags to this list.
|
||||||
@@ -52,6 +46,6 @@ galaxy_info:
|
|||||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||||
# Maximum 20 tags per role.
|
# Maximum 20 tags per role.
|
||||||
|
|
||||||
dependencies: []
|
dependencies: []
|
||||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||||
# if you add dependencies to this list.
|
# if you add dependencies to this list.
|
||||||
57
ansible_apache_formation/tasks/apache.yml
Normal file
57
ansible_apache_formation/tasks/apache.yml
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
---
|
||||||
|
- name: installation
|
||||||
|
package:
|
||||||
|
name: "{{ apache_package_name }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: configuration
|
||||||
|
notify: reload httpd
|
||||||
|
template:
|
||||||
|
src: vhost.conf
|
||||||
|
dest: /etc/httpd/conf.d/vhost.conf
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: apache
|
||||||
|
|
||||||
|
- name: enable service
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
enabled: yes
|
||||||
|
|
||||||
|
- 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
|
||||||
|
template:
|
||||||
|
src: index.html
|
||||||
|
dest: "{{ apache_documentroot }}/index.html"
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: install python passlib package
|
||||||
|
package:
|
||||||
|
name: python-passlib
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: passwd file
|
||||||
|
htpasswd:
|
||||||
|
path: "/etc/httpd/passwd"
|
||||||
|
name: tom
|
||||||
|
password: "123Soleil"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: "apache"
|
||||||
|
|
||||||
|
- name: start service
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: restarted
|
||||||
3
ansible_apache_formation/tasks/main.yml
Normal file
3
ansible_apache_formation/tasks/main.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: apache.yml
|
||||||
|
tags: httpd
|
||||||
1
ansible_apache_formation/templates/index.html
Normal file
1
ansible_apache_formation/templates/index.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<h1>Welcome aboard {{ ansible_hostname }}</h1>
|
||||||
24
ansible_apache_formation/templates/vhost.conf
Normal file
24
ansible_apache_formation/templates/vhost.conf
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName {{ apache_server_name }}
|
||||||
|
ServerAlias www.{{ apache_server_name }}
|
||||||
|
ServerAlias {{ inventory_hostname }}
|
||||||
|
DocumentRoot /var/www/html/{{ apache_server_name }}
|
||||||
|
CustomLog /var/log/httpd/{{ apache_server_name }}_access.log combined
|
||||||
|
ErrorLog /var/log/httpd/{{ apache_server_name }}_error.log
|
||||||
|
<Directory />
|
||||||
|
Options none
|
||||||
|
Allowoverride none
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory {{ apache_documentroot }}>
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
<Directory {{ apache_documentroot }}/Private>
|
||||||
|
Options indexes
|
||||||
|
AuthName "stop"
|
||||||
|
AuthType Basic
|
||||||
|
AuthUserFile /etc/httpd/passwd
|
||||||
|
require valid-user
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
4
ansible_apache_formation/tests/test.yml
Normal file
4
ansible_apache_formation/tests/test.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
- hosts: centos
|
||||||
|
roles:
|
||||||
|
- tconstans.ansible_apache_formation
|
||||||
1
ansible_apache_formation/vars/main.yml
Normal file
1
ansible_apache_formation/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
- name: install apache via ansible playbook
|
|
||||||
hosts: test
|
|
||||||
user: ansible
|
|
||||||
become: true
|
|
||||||
roles:
|
|
||||||
- myapache2
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
apache_vhosts:
|
|
||||||
- servername: 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
|
|
||||||
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
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
Role Name
|
|
||||||
=========
|
|
||||||
|
|
||||||
Rôle de deploiement apache sur une centos.
|
|
||||||
|
|
||||||
more than 1 vhost per host
|
|
||||||
|
|
||||||
Requirements
|
|
||||||
------------
|
|
||||||
|
|
||||||
None
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
Dependencies
|
|
||||||
------------
|
|
||||||
|
|
||||||
None
|
|
||||||
|
|
||||||
Example Playbook
|
|
||||||
----------------
|
|
||||||
|
|
||||||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
|
||||||
|
|
||||||
- hosts: servers
|
|
||||||
roles:
|
|
||||||
- { myapache }
|
|
||||||
|
|
||||||
License
|
|
||||||
-------
|
|
||||||
|
|
||||||
BSD
|
|
||||||
|
|
||||||
Author Information
|
|
||||||
------------------
|
|
||||||
|
|
||||||
Thomas Constans <thomas@opendoor.fr>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
---
|
|
||||||
# defaults file for myapache
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
<h1>hello World</h1>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
---
|
|
||||||
# handlers file for myapache
|
|
||||||
- name: reload httpd
|
|
||||||
service:
|
|
||||||
name: httpd
|
|
||||||
state: reloaded
|
|
||||||
|
|
||||||
- name: reload firewalld
|
|
||||||
service:
|
|
||||||
name: firewalld
|
|
||||||
state: reloaded
|
|
||||||
@@ -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 }}"
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
{% for vhost in apache_vhosts %}
|
|
||||||
<VirtualHost *:{{ http_port }}>
|
|
||||||
ServerName {{ vhost.servername }}
|
|
||||||
ServerAlias {{ vhost.serveralias }}
|
|
||||||
DocumentRoot {{ vhost.documentroot }}
|
|
||||||
CustomLog {{ vhost.accesslog }} combined
|
|
||||||
ErrorLog {{ vhost.errorlog }}
|
|
||||||
<Directory />
|
|
||||||
Options none
|
|
||||||
Allowoverride none
|
|
||||||
Require all denied
|
|
||||||
</Directory>
|
|
||||||
|
|
||||||
<Directory {{ vhost.documentroot }}>
|
|
||||||
Require all granted
|
|
||||||
</Directory>
|
|
||||||
</VirtualHost>
|
|
||||||
{% endfor %}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
- hosts: localhost
|
|
||||||
remote_user: root
|
|
||||||
roles:
|
|
||||||
- myapache
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
---
|
|
||||||
# vars file for myapache
|
|
||||||
http_port: 80
|
|
||||||
Reference in New Issue
Block a user