mise au point atelier condition
This commit is contained in:
24
20_conditions/Readme
Normal file
24
20_conditions/Readme
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
Tâche: Utiliser des conditions
|
||||
Condition: très souvent ;)
|
||||
Norme: éditeur de texte, modules template
|
||||
|
||||
Objectif: Ajouter le support de php à la demande
|
||||
|
||||
Rajouter une variable booleenne apache_use_php.
|
||||
|
||||
Positionnée à "true", cette variable entraîne:
|
||||
- l'installation du paquet php-fpm
|
||||
- le lancement et l'activation du service php-fpm
|
||||
- l'ajout dans la configuration apache des directives suivantes:
|
||||
<code>
|
||||
<FilesMatch \.php$>
|
||||
SetHandler proxy:fcgi://localhost:9000
|
||||
</FilesMatch>
|
||||
</code>
|
||||
|
||||
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.
|
||||
@@ -12,7 +12,7 @@ None
|
||||
|
||||
Role Variables
|
||||
--------------
|
||||
|
||||
apache_user_php - default False
|
||||
http_port: 80
|
||||
servername: orsys.fr
|
||||
serveralias: "www.{{ servername }}"
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
---
|
||||
# defaults file for myapache
|
||||
# defaults file for myapache
|
||||
http_port: 80
|
||||
use_php: false
|
||||
2
20_conditions/myapache4/files/info.php
Normal file
2
20_conditions/myapache4/files/info.php
Normal file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo phpinfo() ;
|
||||
@@ -51,4 +51,8 @@
|
||||
dest: "{{ item.documentroot }}/index.html"
|
||||
mode: 0644
|
||||
with_items:
|
||||
- "{{ apache_vhosts }}"
|
||||
- "{{ apache_vhosts }}"
|
||||
|
||||
- name: include php stuff
|
||||
include_tasks: php.yml
|
||||
when: use_php
|
||||
20
20_conditions/myapache4/tasks/php.yml
Normal file
20
20_conditions/myapache4/tasks/php.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
- name: install php-fpm
|
||||
yum:
|
||||
name: php-fpm
|
||||
state: present
|
||||
|
||||
- name: start php-fpm
|
||||
service:
|
||||
name: php-fpm
|
||||
state: started
|
||||
enabled: true
|
||||
|
||||
- name: create info file
|
||||
copy:
|
||||
src: info.php
|
||||
dest: "{{ item.documentroot }}/info.php"
|
||||
mode: 0644
|
||||
with_items:
|
||||
- "{{ apache_vhosts }}"
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
Allowoverride none
|
||||
Require all denied
|
||||
</Directory>
|
||||
{% if use_php %}
|
||||
<FilesMatch \.php$>
|
||||
SetHandler proxy:fcgi://localhost:9000
|
||||
</FilesMatch>
|
||||
{% endif %}
|
||||
|
||||
<Directory {{ vhost.documentroot }}>
|
||||
Options {{ vhost.documentrootoptions|default( "none" ) }}
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
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).
|
||||
@@ -1,2 +0,0 @@
|
||||
---
|
||||
# defaults file for myphp
|
||||
@@ -1,2 +0,0 @@
|
||||
---
|
||||
# handlers file for myphp
|
||||
@@ -1,57 +0,0 @@
|
||||
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.
|
||||
@@ -1,13 +0,0 @@
|
||||
---
|
||||
# tasks file for myphp
|
||||
- name: import distribution specific variables
|
||||
tags: php
|
||||
include_vars: "{{ ansible_distribution|lower }}.yml"
|
||||
|
||||
- name: install php modules
|
||||
tags: php
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: latest
|
||||
with_items:
|
||||
"{{ packages_list }}"
|
||||
@@ -1,2 +0,0 @@
|
||||
localhost
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- myphp
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
---
|
||||
# distribution dependent vars file for myphp
|
||||
packages_list:
|
||||
- php-gd
|
||||
- php-pdo
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
---
|
||||
# distribution dependent vars file for myphp
|
||||
packages_list:
|
||||
- php-gd
|
||||
- php-mysql
|
||||
@@ -1,2 +0,0 @@
|
||||
---
|
||||
# vars file for myphp
|
||||
@@ -1,6 +0,0 @@
|
||||
|
||||
---
|
||||
# distribution dependent vars file for myphp
|
||||
packages_list:
|
||||
- php-gd
|
||||
- php-pdo
|
||||
@@ -1,9 +0,0 @@
|
||||
---
|
||||
- name: install apache via ansible playbook
|
||||
hosts: test
|
||||
user: ansible
|
||||
become: true
|
||||
roles:
|
||||
- myapache4
|
||||
- myphp
|
||||
|
||||
Reference in New Issue
Block a user