Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0763aebe9 | |||
| 6e42991efa | |||
| 5123a8d280 | |||
| 8e6ed730b1 | |||
| 93ea1c3c8e |
32
Readme.md
32
Readme.md
@@ -1,32 +0,0 @@
|
|||||||
## Variables
|
|
||||||
|
|
||||||
|
|
||||||
*Tâche*: Utiliser des variables pour assouplir l'utilisation d'un rôle
|
|
||||||
|
|
||||||
*Condition*: quand on souhaite adapter un rôle ou un playbook à une situation différente, sans avoir à gérer une autre version du playbook.
|
|
||||||
|
|
||||||
*Norme*: En utilisant les variables
|
|
||||||
|
|
||||||
|
|
||||||
### Préparation
|
|
||||||
|
|
||||||
Récupérer le rôle ansible_apache_formation:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/tconstans/ansible_apache_formation.git
|
|
||||||
```
|
|
||||||
|
|
||||||
### Pratique:
|
|
||||||
|
|
||||||
Ce rôle présente quelques problèmes à identifier.
|
|
||||||
|
|
||||||
Remplacer ces éléments répétés dans les différents éléments par des variables judicieusement nommées.
|
|
||||||
|
|
||||||
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 ?
|
|
||||||
|
|
||||||
### Performance
|
|
||||||
|
|
||||||
Il est désormais facile d'adapter le rôle pour qu'il traite un autre site que www.orsys.fr
|
|
||||||
|
|
||||||
Solution: voir branche "solution"
|
|
||||||
|
|
||||||
47
ansible_apache_formation/README.md
Normal file
47
ansible_apache_formation/README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
Role Name
|
||||||
|
=========
|
||||||
|
apache_formation
|
||||||
|
|
||||||
|
NOT FOR PRODUCTION USE
|
||||||
|
|
||||||
|
This role has been designed for training purpose
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
apache_server_name - nom du site
|
||||||
|
|
||||||
|
apache_service_name - nom du service
|
||||||
|
apache_package_name - nom du package
|
||||||
|
apache_config_dir - répertoire de config
|
||||||
|
apache_group_name - nom du groupe apache
|
||||||
|
#apache_listen_port - port d'écoute - defaut 80
|
||||||
|
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
None
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
---
|
||||||
|
- hosts: test
|
||||||
|
roles:
|
||||||
|
- apache_formation
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Thomas Constans <thomas@opendoor.fr>
|
||||||
3
ansible_apache_formation/defaults/main.yml
Normal file
3
ansible_apache_formation/defaults/main.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#/home/formation/ansible_apache_formation/defaults/main.yml
|
||||||
|
---
|
||||||
|
apache_listen_port: 80
|
||||||
5
ansible_apache_formation/handlers/main.yml
Normal file
5
ansible_apache_formation/handlers/main.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: reload httpd
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: reloaded
|
||||||
51
ansible_apache_formation/meta/main.yml
Normal file
51
ansible_apache_formation/meta/main.yml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
galaxy_info:
|
||||||
|
role_name: apache_formation
|
||||||
|
author: Thomas Constans <thomas@opendoor.fr>
|
||||||
|
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
|
||||||
|
# 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: GPLv2
|
||||||
|
|
||||||
|
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: EL
|
||||||
|
versions:
|
||||||
|
- 7
|
||||||
|
|
||||||
|
galaxy_tags: [apache,training]
|
||||||
|
# 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
ansible_apache_formation/tasks/apache.yml
Normal file
60
ansible_apache_formation/tasks/apache.yml
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
---
|
||||||
|
- name: import OS variables
|
||||||
|
include_vars: "{{ ansible_distribution |lower }}{{ ansible_distribution_major_version }}.yml"
|
||||||
|
|
||||||
|
- name: installation
|
||||||
|
package:
|
||||||
|
name: "{{ apache_package_name }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: configuration
|
||||||
|
notify: reload httpd
|
||||||
|
template:
|
||||||
|
src: vhost.conf
|
||||||
|
dest: "{{ apache_config_dir }}/vhost.conf"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: "{{ apache_group_name }}"
|
||||||
|
|
||||||
|
- 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: "/var/www/{{ apache_server_name }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: create index file
|
||||||
|
template:
|
||||||
|
src: index.html
|
||||||
|
dest: "/var/www/{{ apache_server_name }}/index.html"
|
||||||
|
mode: 0644
|
||||||
|
|
||||||
|
- name: install python passlib package
|
||||||
|
package:
|
||||||
|
name: "{{ python_passlib_package }}"
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: passwd file
|
||||||
|
htpasswd:
|
||||||
|
path: "{{ apache_config_dir }}/passwd"
|
||||||
|
name: tom
|
||||||
|
password: "123Soleil"
|
||||||
|
mode: 0640
|
||||||
|
owner: root
|
||||||
|
group: "{{ apache_group_name }}"
|
||||||
|
|
||||||
|
- name: start service
|
||||||
|
service:
|
||||||
|
name: "{{ apache_service_name }}"
|
||||||
|
state: started
|
||||||
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>
|
||||||
23
ansible_apache_formation/templates/vhost.conf
Normal file
23
ansible_apache_formation/templates/vhost.conf
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
ServerName {{ apache_server_name }}"
|
||||||
|
ServerAlias www.{{ apache_server_name }}"
|
||||||
|
DocumentRoot /var/www/{{ apache_server_name }}"
|
||||||
|
CustomLog /var/log/{{ apache_service_name }}/{{ apache_server_name }}"_access.log combined
|
||||||
|
ErrorLog /var/log/{{ apache_service_name }}/{{ apache_server_name }}"_error.log
|
||||||
|
<Directory />
|
||||||
|
Options none
|
||||||
|
Allowoverride none
|
||||||
|
Require all denied
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
<Directory /var/www/{{ apache_server_name }}">
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
<Directory /var/www/{{ apache_server_name }}"/Private>
|
||||||
|
Options indexes
|
||||||
|
AuthName "stop"
|
||||||
|
AuthType Basic
|
||||||
|
AuthUserFile {{ apache_config_dir }}/passwd
|
||||||
|
require valid-user
|
||||||
|
</Directory>
|
||||||
|
</VirtualHost>
|
||||||
2
ansible_apache_formation/tests/inventory
Normal file
2
ansible_apache_formation/tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
localhost
|
||||||
|
|
||||||
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
|
||||||
6
ansible_apache_formation/vars/almalinux9.yml
Normal file
6
ansible_apache_formation/vars/almalinux9.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#/home/formation/ansible_apache_formation/vars/centos8.yml
|
||||||
|
python_passlib_package: python3-passlib
|
||||||
|
apache_service_name: httpd
|
||||||
|
apache_package_name: httpd
|
||||||
|
apache_config_dir: /etc/httpd/conf.d
|
||||||
|
apache_group_name: apache
|
||||||
1
ansible_apache_formation/vars/centos7.yml
Normal file
1
ansible_apache_formation/vars/centos7.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
python_passlib_package: python-passlib
|
||||||
6
ansible_apache_formation/vars/centos8.yml
Normal file
6
ansible_apache_formation/vars/centos8.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#/home/formation/ansible_apache_formation/vars/centos8.yml
|
||||||
|
python_passlib_package: python3-passlib
|
||||||
|
apache_service_name: httpd
|
||||||
|
apache_package_name: httpd
|
||||||
|
apache_config_dir: /etc/httpd/conf.d
|
||||||
|
apache_group_name: apache
|
||||||
7
ansible_apache_formation/vars/debian10.yml
Normal file
7
ansible_apache_formation/vars/debian10.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#/home/formation/ansible_apache_formation/vars/debian10.yml
|
||||||
|
python_passlib_package: python3-passlib
|
||||||
|
apache_service_name: apache2
|
||||||
|
apache_package_name: apache2
|
||||||
|
apache_config_dir: /etc/apache2/sites-enabled
|
||||||
|
apache_group_name: www-data
|
||||||
|
|
||||||
1
ansible_apache_formation/vars/main.yml
Normal file
1
ansible_apache_formation/vars/main.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
4
apache.yml
Normal file
4
apache.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
- hosts: cibles
|
||||||
|
role:
|
||||||
|
- ansible_apache_formation
|
||||||
2
host_vars/centos1.formation.opendoor.fr.yml
Normal file
2
host_vars/centos1.formation.opendoor.fr.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
apache_server_name: orsys.fr
|
||||||
|
apache_documentroot: /srv/www/orsys.fr
|
||||||
Reference in New Issue
Block a user