diff --git a/webapps/README.md b/webapps/README.md deleted file mode 100644 index 2c74fa01..00000000 --- a/webapps/README.md +++ /dev/null @@ -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 diff --git a/webapps/defaults/main.yml b/webapps/defaults/main.yml deleted file mode 100644 index 1c25888f..00000000 --- a/webapps/defaults/main.yml +++ /dev/null @@ -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" - diff --git a/webapps/handlers/main.yml b/webapps/handlers/main.yml deleted file mode 100644 index b1d39d12..00000000 --- a/webapps/handlers/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# handlers file for webapps diff --git a/webapps/tasks/main.yml b/webapps/tasks/main.yml deleted file mode 100644 index a86da0fd..00000000 --- a/webapps/tasks/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- - -- include: wordpress.yml - when: webapps_wordpress_install diff --git a/webapps/tasks/wordpress.yml b/webapps/tasks/wordpress.yml deleted file mode 100644 index e85433c1..00000000 --- a/webapps/tasks/wordpress.yml +++ /dev/null @@ -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' - diff --git a/webapps/vars/main.yml b/webapps/vars/main.yml deleted file mode 100644 index 5ec52e44..00000000 --- a/webapps/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for webapps diff --git a/webapps/wordpress/defaults/main.yml b/webapps/wordpress/defaults/main.yml new file mode 100644 index 00000000..b7d6f998 --- /dev/null +++ b/webapps/wordpress/defaults/main.yml @@ -0,0 +1,4 @@ +--- +wordpress_host: "{{ ansible_fqdn }}" +wordpress_title: "Wordpress Saas Evolix" +wordpress_email: "root@localhost" diff --git a/webapps/meta/main.yml b/webapps/wordpress/meta/main.yml similarity index 90% rename from webapps/meta/main.yml rename to webapps/wordpress/meta/main.yml index a8204bf9..73c6e08f 100644 --- a/webapps/meta/main.yml +++ b/webapps/wordpress/meta/main.yml @@ -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 diff --git a/webapps/wordpress/tasks/main.yml b/webapps/wordpress/tasks/main.yml new file mode 100644 index 00000000..0de874e8 --- /dev/null +++ b/webapps/wordpress/tasks/main.yml @@ -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 }}