initial commit

This commit is contained in:
2020-09-22 15:42:05 +02:00
commit 2f2d25fc40
14 changed files with 232 additions and 0 deletions

12
Readme Normal file
View File

@@ -0,0 +1,12 @@
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.

7
apache.yml Normal file
View File

@@ -0,0 +1,7 @@
---
- name: install apache via ansible playbook
hosts: test
user: ansible
become: true
roles:
- myapache2

11
host_vars/cible1 Normal file
View 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
documentroot: /var/www/html/thomas.fr
accesslog: /var/log/httpd/access_thomas.fr_log
errorlog: /var/log/httpd/error_thomas.fr_log

11
host_vars/cible2 Normal file
View File

@@ -0,0 +1,11 @@
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

49
myapache2/README.md Normal file
View File

@@ -0,0 +1,49 @@
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>

View File

@@ -0,0 +1,2 @@
---
# defaults file for myapache

View File

@@ -0,0 +1 @@
<h1>hello World</h1>

View File

@@ -0,0 +1,11 @@
---
# handlers file for myapache
- name: reload httpd
service:
name: httpd
state: reloaded
- name: reload firewalld
service:
name: firewalld
state: reloaded

57
myapache2/meta/main.yml Normal file
View 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.

43
myapache2/tasks/main.yml Normal file
View File

@@ -0,0 +1,43 @@
---
# 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 }}"

View File

@@ -0,0 +1,18 @@
{% 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 %}

View File

@@ -0,0 +1,2 @@
localhost

5
myapache2/tests/test.yml Normal file
View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- myapache

3
myapache2/vars/main.yml Normal file
View File

@@ -0,0 +1,3 @@
---
# vars file for myapache
http_port: 80