forked from evolix/ansible-roles
wordpress: refactoring into role
This commit is contained in:
parent
3b4bf6d13a
commit
104a5c962e
|
@ -1,13 +0,0 @@
|
|||
# webapps
|
||||
|
||||
Install popular webapps
|
||||
|
||||
## Tasks
|
||||
|
||||
Tasks are extracted in several files, included in `tasks/main.yml` :
|
||||
|
||||
* `wordpress.yml` : wordpress installation
|
||||
|
||||
## Available variables
|
||||
|
||||
* `webapp_wordpress_install` : enable wordpress installation
|
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
webapps_wordpress_install: False
|
||||
webapps_wordpress_version: 4.7-branch
|
||||
webapps_wordpress_upstream: https://github.com/WordPress/WordPress
|
||||
webapps_wordpress_upstream_default_title: "new blog Evolix SaaS"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
---
|
||||
# handlers file for webapps
|
|
@ -1,4 +0,0 @@
|
|||
---
|
||||
|
||||
- include: wordpress.yml
|
||||
when: webapps_wordpress_install
|
|
@ -1,48 +0,0 @@
|
|||
#- name: Init global variables
|
||||
# include: './tasks/var_common.yml'
|
||||
|
||||
- name: init dir_wpcli
|
||||
set_fact: dir_wpcli="{{ dir }}/wp-cli"
|
||||
|
||||
- debug: var=dir_wpcli
|
||||
when: debug_mode
|
||||
tags: debug_mode
|
||||
|
||||
- name: Git clone Wordpress repository
|
||||
include: './tasks/git.yml'
|
||||
vars:
|
||||
service_git: WordPress
|
||||
url_git: "{{ webapps_wordpress_upstream }}"
|
||||
dest_git: "{{ dir_www }}"
|
||||
version_git: "{{ webapps_wordpress_version }}"
|
||||
|
||||
- name: Creation directory wp-cli
|
||||
file: >
|
||||
path: "{{ dir_wpcli }}"
|
||||
state: directory
|
||||
|
||||
- name: Download wp-cli.phar
|
||||
include: './tasks/download.yml'
|
||||
vars:
|
||||
url: 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar'
|
||||
dest: "{{ dir_wpcli }}"
|
||||
|
||||
- name: Configuration for db
|
||||
shell: >
|
||||
php wp-cli.phar core config --dbname="{{ db_name }}" --dbuser="{{ db_user }}" --dbpass="{{ db_pwd }}" --dbhost="{{ db_host }}" --path="{{ dir_www }}"
|
||||
chdir: "{{ dir_wpcli }}"
|
||||
|
||||
- name: Wordpress site installation
|
||||
shell: >
|
||||
php wp-cli.phar core install --url="{{ host }}" --title="{{ site_title }}" --admin_user="admin" --admin_password="{{ admin_pwd }}" --admin_email="{{ user }}@{{ ansible_fqdn }}" --skip-email --path="{{ dir_www }}"
|
||||
chdir: "{{ dir_wpcli }}"
|
||||
|
||||
- name: Init variables to sending the email about the installation
|
||||
include: './tasks/var_email_install.yml'
|
||||
vars:
|
||||
admin_user: 'admin'
|
||||
type: 'Installation'
|
||||
|
||||
- name: Send email
|
||||
include: './tasks/email.yml'
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
---
|
||||
# vars file for webapps
|
4
webapps/wordpress/defaults/main.yml
Normal file
4
webapps/wordpress/defaults/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
wordpress_host: "{{ ansible_fqdn }}"
|
||||
wordpress_title: "Wordpress Saas Evolix"
|
||||
wordpress_email: "root@localhost"
|
|
@ -1,6 +1,6 @@
|
|||
galaxy_info:
|
||||
author: Evolix
|
||||
description: your description
|
||||
description: Install Wordpress site
|
||||
|
||||
issue_tracker_url: https://forge.evolix.org/projects/ansible-roles/issues
|
||||
|
78
webapps/wordpress/tasks/main.yml
Normal file
78
webapps/wordpress/tasks/main.yml
Normal file
|
@ -0,0 +1,78 @@
|
|||
---
|
||||
- name: Create bin dir
|
||||
file:
|
||||
state: directory
|
||||
dest: "{{ ansible_env.HOME }}/bin"
|
||||
mode: "0750"
|
||||
|
||||
- name: Download wp-cli
|
||||
get_url:
|
||||
url: "https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
|
||||
dest: "{{ ansible_env.HOME }}/bin/wp-cli.phar"
|
||||
mode: "0750"
|
||||
|
||||
- name: Download Wordpress
|
||||
shell: 'php {{ ansible_env.HOME }}/bin/wp-cli.phar core download --locale=fr_FR --version=latest --path={{ ansible_env.HOME }}/www'
|
||||
args:
|
||||
creates: "{{ ansible_env.HOME }}/www/index.php"
|
||||
|
||||
- name: Retrieve .my.cnf
|
||||
fetch:
|
||||
src: "{{ ansible_env.HOME }}/.my.cnf"
|
||||
dest: "/tmp/wordpress-{{ ansible_user }}.cnf"
|
||||
flat: yes
|
||||
|
||||
- name: Generate random password
|
||||
command: apg -n1 -m 12 -M SCN
|
||||
register: shell_password
|
||||
changed_when: false
|
||||
|
||||
- name: Read mysql config from .my.cnf
|
||||
set_fact:
|
||||
db_host: "{{ lookup('ini', 'host section=client file=/tmp/wordpress-{{ ansible_user }}.cnf default=127.0.0.1') }}"
|
||||
db_user: "{{ lookup('ini', 'user section=client file=/tmp/wordpress-{{ ansible_user }}.cnf default={{ ansible_user }}') }}"
|
||||
db_pwd: "{{ lookup('ini', 'password section=client file=/tmp/wordpress-{{ ansible_user }}.cnf') }}"
|
||||
db_name: "{{ lookup('ini', 'database section=mysql file=/tmp/wordpress-{{ ansible_user }}.cnf default={{ ansible_user }}') }}"
|
||||
admin_pwd: "{{ shell_password.stdout }}"
|
||||
|
||||
- name: Remove local .my.cnf
|
||||
file:
|
||||
path: "/tmp/wordpress-{{ ansible_user }}.cnf"
|
||||
state: absent
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Configure Wordpress (wp-config.php)
|
||||
shell: 'php {{ ansible_env.HOME }}/bin/wp-cli.phar core config --path={{ ansible_env.HOME }}/www/ --dbhost={{ db_host }} --dbuser={{ db_user }} --dbpass={{ db_pwd }} --dbname={{ db_name }}'
|
||||
args:
|
||||
creates: "{{ ansible_env.HOME }}/www/wp-config.php"
|
||||
|
||||
- name: Check if Wordpress is up to date
|
||||
shell: 'php {{ ansible_env.HOME }}/bin/wp-cli.phar core check-update --path={{ ansible_env.HOME }}/www | grep -q Success'
|
||||
register: check_version
|
||||
check_mode: no
|
||||
failed_when: false
|
||||
changed_when: check_version.rc
|
||||
|
||||
- name: Update Wordpress
|
||||
shell: 'php {{ ansible_env.HOME }}/bin/wp-cli.phar core update --path={{ ansible_env.HOME }}/www'
|
||||
args:
|
||||
removes: "{{ ansible_env.HOME }}/www/index.php"
|
||||
when: check_version.rc
|
||||
|
||||
- name: Configure site
|
||||
shell: 'php {{ ansible_env.HOME }}/bin/wp-cli.phar core install --url={{ wordpress_host | quote }} --title={{ wordpress_title | quote }} --admin_user=admin --admin_password={{ admin_pwd | quote }} --admin_email={{ wordpress_email }} --path={{ ansible_env.HOME }}/www'
|
||||
|
||||
- name: Send a summary mail
|
||||
mail:
|
||||
host: 'localhost'
|
||||
port: 25
|
||||
to: "{{ wordpress_email }}"
|
||||
from: "{{ ansible_user }}@{{ ansible_fqdn }}"
|
||||
subject: "Accès Wordpress {{ wordpress_host }}"
|
||||
body: |
|
||||
Installation du Wordpress {{ ansible_user }} sur {{ ansible_fqdn }}
|
||||
|
||||
Server : {{ ansible_fqdn }}
|
||||
Url : http://{{ wordpress_host }}
|
||||
Utilisateur : admin
|
||||
Mot de passe : {{ admin_pwd }}
|
Loading…
Reference in a new issue