Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 920af07166 | |||
| 3bc092ada5 | |||
| db9f049e68 | |||
| 6d279c75bb |
29
Readme.md
29
Readme.md
@@ -1,29 +0,0 @@
|
||||
## Variables complexes
|
||||
|
||||
**Tâche**: Utiliser des variables
|
||||
|
||||
**Condition**: très souvent ;)
|
||||
|
||||
**Norme**: éditeur de texte, modules template, variable d'inventaire
|
||||
|
||||
Préparation: récupérer la solution de l'atelier sib_15_roles:
|
||||
|
||||
```bash
|
||||
cd
|
||||
git clone -b solution https://infra.opendoor.fr/git/tom/sib_15_roles apache_var_comp
|
||||
cd apache_var_comp
|
||||
|
||||
```
|
||||
|
||||
Objectif: Modifier le rôle pour que l'on puisse héberger plusieurs vhost sur une même machine. Les éléments suivants seront propre à chaque vhost:
|
||||
* servername
|
||||
* serveralias
|
||||
* documentroot
|
||||
* log d'accès et d'erreur
|
||||
|
||||
Prérequis:
|
||||
|
||||
Validation: le playbook s'exécute correctement sur nos cibles.
|
||||
Chaque cible héberge plusieurs sites différents.
|
||||
|
||||
Solution: voir branche "solution"
|
||||
5
apache.yml
Normal file
5
apache.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: install apache via ansible playbook
|
||||
hosts: all
|
||||
roles:
|
||||
- apache
|
||||
45
apache/README.md
Normal file
45
apache/README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
Role Name
|
||||
=========
|
||||
|
||||
Rôle de deploiement apache sur une centos.
|
||||
|
||||
1 seul vhost
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
None
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
http_port: 80
|
||||
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>
|
||||
2
apache/defaults/main.yml
Normal file
2
apache/defaults/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# defaults file for myapache
|
||||
1
apache/files/index.html
Normal file
1
apache/files/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>hello World</h1>
|
||||
11
apache/handlers/main.yml
Normal file
11
apache/handlers/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
# handlers file for myapache
|
||||
- name: reload httpd
|
||||
service:
|
||||
name: "{{ apache_service_name }}"
|
||||
state: reloaded
|
||||
|
||||
- name: reload firewalld
|
||||
service:
|
||||
name: firewalld
|
||||
state: reloaded
|
||||
57
apache/meta/main.yml
Normal file
57
apache/meta/main.yml
Normal file
@@ -0,0 +1,57 @@
|
||||
galaxy_info:
|
||||
author: your name
|
||||
description: your description
|
||||
company: your company (optional)
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Some suggested licenses:
|
||||
# - BSD (default)
|
||||
# - MIT
|
||||
# - GPLv2
|
||||
# - GPLv3
|
||||
# - Apache
|
||||
# - CC-BY
|
||||
license: license (GPLv2, CC-BY, etc)
|
||||
|
||||
min_ansible_version: 1.2
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
# Optionally specify the branch Galaxy will use when accessing the GitHub
|
||||
# repo for this role. During role install, if no tags are available,
|
||||
# Galaxy will use this branch. During import Galaxy will access files on
|
||||
# this branch. If Travis integration is configured, only notifications for this
|
||||
# branch will be accepted. Otherwise, in all cases, the repo's default branch
|
||||
# (usually master) will be used.
|
||||
#github_branch:
|
||||
|
||||
#
|
||||
# platforms is a list of platforms, and each platform has a name and a list of versions.
|
||||
#
|
||||
# platforms:
|
||||
# - name: Fedora
|
||||
# versions:
|
||||
# - all
|
||||
# - 25
|
||||
# - name: SomePlatform
|
||||
# versions:
|
||||
# - all
|
||||
# - 1.0
|
||||
# - 7
|
||||
# - 99.99
|
||||
|
||||
galaxy_tags: []
|
||||
# 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
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
||||
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 }}"
|
||||
21
apache/templates/vhost.conf.jj
Normal file
21
apache/templates/vhost.conf.jj
Normal file
@@ -0,0 +1,21 @@
|
||||
{% for vhost in apache_vhosts %}
|
||||
<VirtualHost *:{{ http_port }}>
|
||||
ServerName {{ vhost.servername }}
|
||||
{% for alias in vhost.serveralias %}
|
||||
ServerAlias {{ alias }}
|
||||
{% endfor %}
|
||||
DocumentRoot {{ vhost.documentroot }}
|
||||
CustomLog {{ vhost.accesslog }} combined
|
||||
ErrorLog {{ vhost.errorlog }}
|
||||
<Directory />
|
||||
Options none
|
||||
Allowoverride none
|
||||
Require all denied
|
||||
</Directory>
|
||||
|
||||
<Directory {{ vhost.documentroot }}>
|
||||
Options {{ vhost.documentrootoptions|default( "none" ) }}
|
||||
Require all granted
|
||||
</Directory>
|
||||
</VirtualHost>
|
||||
{% endfor %}
|
||||
2
apache/tests/inventory
Normal file
2
apache/tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
||||
5
apache/tests/test.yml
Normal file
5
apache/tests/test.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- myapache
|
||||
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/
|
||||
3
apache/vars/main.yml
Normal file
3
apache/vars/main.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
---
|
||||
# vars file for myapache
|
||||
http_port: 80
|
||||
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
|
||||
11
host_vars/centos1.formation.opendoor.fr.yml
Normal file
11
host_vars/centos1.formation.opendoor.fr.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
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, thomas.org ]
|
||||
documentroot: /var/www/html/thomas.fr
|
||||
accesslog: /var/log/httpd/access_thomas.fr_log
|
||||
errorlog: /var/log/httpd/error_thomas.fr_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
|
||||
|
||||
Reference in New Issue
Block a user