3 Commits

Author SHA1 Message Date
8ecd8acbd2 cleanup 2021-09-17 10:39:12 +02:00
fd95cee4b4 mise au point readme 2021-09-17 10:07:09 +02:00
f4420ee8e5 mise au point solution tp conversion playbook apache en role 2021-09-17 09:55:17 +02:00
21 changed files with 133 additions and 118 deletions

View File

@@ -1,6 +1,6 @@
## Rôles ## Rôles
**Tâche**: Écrire un rôle **Tâche**: Écrire / Convertir un rôle
**Condition**: pour améliorer l'organisation et la maintenance de nos playbooks **Condition**: pour améliorer l'organisation et la maintenance de nos playbooks
@@ -8,13 +8,7 @@
## Pratique: ## Pratique:
Convertir en un rôle nommé "apache" le 1er playbook mis au point lors de l'atelier "handlers". Convertir en un rôle nommé "sib.apache" le playbook apache.yml".
Vous pouvez récupérer ce playbook via la commande:
```bash
git clone -b solution https://infra.opendoor.fr/git/tom/sib_12_handlers
```
## Performance ## Performance

View File

@@ -1,5 +1,5 @@
--- ---
- hosts: centos - hosts: centos
name: install apache from role name: install apache
roles: roles:
- tco.apache - sib.apache

38
sib.apache/README.md Normal file
View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
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:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,2 @@
---
# defaults file for sib.apache

View File

@@ -0,0 +1,6 @@
---
# handlers file for sib.apache
- name: restart httpd
service:
name: httpd
state: restarted

55
sib.apache/tasks/main.yml Normal file
View File

@@ -0,0 +1,55 @@
---
# tasks file for sib.apache
- name: install apache
yum:
name: httpd
state: present
- name: conf httpd
template:
src: vhost.conf
dest: /etc/httpd/conf.d/vhost.conf
mode: 0640
owner: root
group: apache
notify: restart httpd
- name: activate apache
service:
name: httpd
enabled: yes
state: started
- name: setup firewall
block:
- name: install firewalld packages
yum:
name:
- python3-firewall
- firewalld
state: present
- name: enable firewalld service
service:
name: firewalld
enabled: true
state: started
- name: open firewall port
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
ignore_errors: true
- name: create documentroot
file:
name: /var/www/html/example.org/
state: directory
- name: copy index file
template:
src: index.txt
dest: /var/www/html/example.org/index.html
mode: 0644

View File

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

View File

@@ -0,0 +1,24 @@
<VirtualHost *:80>
ServerName example.fr
ServerAlias www.example.fr
ServerAlias {{ inventory_hostname }}
DocumentRoot /var/www/html/example.fr
CustomLog /var/log/httpd/example.fr_access.log combined
ErrorLog /var/log/httpd/example.fr_error.log
<Directory />
Options none
Allowoverride none
Require all denied
</Directory>
<Directory /var/www/html/example.fr>
Require all granted
</Directory>
<Directory /var/www/html/example.fr/Private>
Options indexes
AuthName "stop"
AuthType Basic
AuthUserFile /etc/httpd/passwd
require valid-user
</Directory>
</VirtualHost>

View File

@@ -2,4 +2,4 @@
- hosts: localhost - hosts: localhost
remote_user: root remote_user: root
roles: roles:
- tco.apache - sib.apache

2
sib.apache/vars/main.yml Normal file
View File

@@ -0,0 +1,2 @@
---
# vars file for sib.apache

View File

@@ -1,38 +0,0 @@
Role Name
=========
Install apache
Requirements
------------
None
Role Variables
--------------
None
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: centos
roles:
- tco.apache
License
-------
BSD
Author Information
------------------
Thomas C <thomas@opendoor.fr>

View File

@@ -1,2 +0,0 @@
---
# defaults file for tco.apache

View File

@@ -1,3 +0,0 @@
#Configuration sudo
# en nopassword pour ansible
ansible ALL=(ALL) NOPASSWD: ALL

View File

@@ -1,6 +0,0 @@
---
# handlers file for tco
- name: restart apache
service:
name: httpd
state: restarted

View File

@@ -1,39 +0,0 @@
---
- name: install apache
yum:
name: httpd
state: latest
- name: conf httpd
template:
src: vhost.conf
dest: /etc/httpd/conf.d/vhost.conf
mode: 0640
owner: root
group: apache
notify: restart apache
- name: activate apache
service:
name: httpd
enabled: yes
state: started
- name: open firewall port
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
ignore_errors: yes
- name: create documentroot
file:
name: /var/www/html/orsys.fr
state: directory
- name: create index file
template:
src: index.txt
dest: /var/www/html/orsys.fr/index.html
mode: 0644

View File

@@ -1 +0,0 @@
<span style="text-align: center;background-color: #FD5401; font-size: 42px;">Hello World</span>

View File

@@ -1,16 +0,0 @@
<VirtualHost *:80>
ServerName orsys.fr
ServerAlias www.orsys.fr
DocumentRoot /var/www/html/orsys.fr/
CustomLog /var/log/httpd/orsys.fr_access.log combined
ErrorLog /var/log/httpd/orsys.fr_error.log
<Directory />
Options none
Allowoverride none
Require all denied
</Directory>
<Directory /var/www/html/orsys.fr>
Require all granted
</Directory>
</VirtualHost>

View File

@@ -1,2 +0,0 @@
---
# vars file for tco.apache