From 1eecec2de83612235aa328358c84ff732a6c5296 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Fri, 23 Oct 2015 21:23:32 +0300 Subject: [PATCH] Correct EOL in wp-config.php. Use mysql role instead of mysql tasks file. Daily backup job is a script now. Merge php tasks file to main tasks file. --- README.rst | 5 +- defaults/main.yml | 3 + files/backup.sh | 3 + handlers/main.yml | 5 - meta/main.yml | 6 +- tasks/main.yml | 64 ++++++++----- tasks/mysql.yml | 26 ------ tasks/php.yml | 30 ------ templates/wp-config.php.j2 | 185 +++++++++++++++++++------------------ 9 files changed, 149 insertions(+), 178 deletions(-) create mode 100644 files/backup.sh delete mode 100644 tasks/mysql.yml delete mode 100644 tasks/php.yml diff --git a/README.rst b/README.rst index f3d289d..0deedc6 100644 --- a/README.rst +++ b/README.rst @@ -14,7 +14,10 @@ Debian Jessie. Role Variables -------------- -None. +:: + + fqdn: ansible_fqdn #Site FQDN. + force_ssl: True #Force SSL for site URL. Dependencies ------------ diff --git a/defaults/main.yml b/defaults/main.yml index fd62c7b..0ffee86 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,5 @@ --- # defaults file for wordpress + +fqdn: '{{ ansible_fqdn }}' +force_ssl: True diff --git a/files/backup.sh b/files/backup.sh new file mode 100644 index 0000000..852a597 --- /dev/null +++ b/files/backup.sh @@ -0,0 +1,3 @@ +#!/bin/sh -e +cd /var/www +tar -cf /var/backups/wordpress.tar wordpress diff --git a/handlers/main.yml b/handlers/main.yml index bd88202..7222903 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -10,8 +10,3 @@ service: name: php5-fpm state: restarted - -- name: Restart MySQL - service: - name: mysql - state: restarted diff --git a/meta/main.yml b/meta/main.yml index 59e050d..1a3c48b 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -11,4 +11,8 @@ galaxy_info: - jessie categories: - web -dependencies: [] +dependencies: + - role: mysql + mysql_database: wordpress + mysql_user: wordpress + mysql_password: wordpress diff --git a/tasks/main.yml b/tasks/main.yml index dbec7a7..8c1ea32 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,9 +1,19 @@ --- -# tasks file for wordpress +# tasks file for ansible-wordpress -- include: php.yml - -- include: mysql.yml +- name: apt install prerequisites + apt: + name: '{{ item }}' + state: present + update_cache: yes + cache_valid_time: 3600 + with_items: + - nginx-light + - php5-fpm + - php5-cli + - php5-mysql + - php5-gd + - cron - name: Get tarball get_url: @@ -12,8 +22,10 @@ owner: root group: root mode: '0644' + register: wordpress_download - name: Unpack tarball + when: wordpress_download|changed unarchive: copy: no dest: /var/www @@ -21,7 +33,6 @@ owner: root group: root mode: '0755' - creates: /var/www/wordpress/index.php - name: Configure Wordpress template: @@ -38,24 +49,27 @@ recurse: yes state: directory -- name: Create backup destination - file: - path: /var/backups - state: directory +- name: Add daily backup job + copy: + src: backup.sh + dest: /etc/cron.daily/wordpress + owner: root + group: root mode: '0755' - owner: nobody - group: nogroup - -- name: Add daily Wordpress backup and cleanup jobs - cron: - special_time: daily - user: nobody - name: '{{ item.name }}' - job: '{{ item.job }}' - with_items: - - name: Daily MySQL backup - job: 'mysqldump --user root --single-transaction --force wordpress > /var/backups/wordpress-$(date -I).sql' - - name: Daily backup cleanup - job: 'find /var/backups -atime 30 -delete' - - name: Daily Wordpress backup - job: 'tar -cf /var/backups/wordpress-$(date -I).tar /var/www/wordpress' + +- name: Disable default Nginx site + file: + path: /etc/nginx/sites-enabled/default + state: absent + notify: + - Restart Nginx + +- name: Add Wordpress site to Nginx + template: + src: wordpress.j2 + dest: /etc/nginx/sites-enabled/wordpress + owner: root + group: root + mode: '0644' + notify: + - Restart Nginx diff --git a/tasks/mysql.yml b/tasks/mysql.yml deleted file mode 100644 index 9aad647..0000000 --- a/tasks/mysql.yml +++ /dev/null @@ -1,26 +0,0 @@ ---- -- name: apt-get install mysql - apt: - name: '{{ item }}' - state: present - update_cache: yes - cache_valid_time: 3600 - with_items: - - mysql-server - - mysql-client - - python-mysqldb - - anacron - -- name: Create Wordpress MySQL database - mysql_db: - collation: utf8_general_ci - encoding: utf8 - name: wordpress - state: present - -- name: Create Wordpress MySQL account - mysql_user: - name: wordpress - password: wordpress - priv: 'wordpress.*:SELECT,INSERT,UPDATE,DELETE,CREATE,INDEX' - state: present diff --git a/tasks/php.yml b/tasks/php.yml deleted file mode 100644 index 0705cd5..0000000 --- a/tasks/php.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -- name: apt-get install php-fpm, nginx prerequisites - apt: - name: '{{ item }}' - state: present - update_cache: yes - cache_valid_time: 3600 - with_items: - - nginx-light - - php5-fpm - - php5-cli - - php5-mysql - - php5-gd - -- name: Disable default Nginx site - file: - path: /etc/nginx/sites-enabled/default - state: absent - notify: - - Restart Nginx - -- name: Add Wordpress site to Nginx - template: - src: wordpress.j2 - dest: /etc/nginx/sites-enabled/wordpress - owner: root - group: root - mode: '0644' - notify: - - Restart Nginx diff --git a/templates/wp-config.php.j2 b/templates/wp-config.php.j2 index 02e9699..aa04290 100644 --- a/templates/wp-config.php.j2 +++ b/templates/wp-config.php.j2 @@ -1,90 +1,95 @@ -<?php -/** - * The base configuration for WordPress - * - * The wp-config.php creation script uses this file during the - * installation. You don't have to use the web site, you can - * copy this file to "wp-config.php" and fill in the values. - * - * This file contains the following configurations: - * - * * MySQL settings - * * Secret keys - * * Database table prefix - * * ABSPATH - * - * @link https://codex.wordpress.org/Editing_wp-config.php - * - * @package WordPress - */ - -// ** MySQL settings - You can get this info from your web host ** // -/** The name of the database for WordPress */ -define('DB_NAME', 'wordpress'); - -/** MySQL database username */ -define('DB_USER', 'wordpress'); - -/** MySQL database password */ -define('DB_PASSWORD', 'wordpress'); - -/** MySQL hostname */ -define('DB_HOST', 'localhost'); - -/** Database Charset to use in creating database tables. */ -define('DB_CHARSET', 'utf8'); - -/** The Database Collate type. Don't change this if in doubt. */ -define('DB_COLLATE', 'utf8_general_ci'); - -/**#@+ - * Authentication Unique Keys and Salts. - * - * Change these to different unique phrases! - * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} - * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. - * - * @since 2.6.0 - */ -define('AUTH_KEY', 'put your unique phrase here'); -define('SECURE_AUTH_KEY', 'put your unique phrase here'); -define('LOGGED_IN_KEY', 'put your unique phrase here'); -define('NONCE_KEY', 'put your unique phrase here'); -define('AUTH_SALT', 'put your unique phrase here'); -define('SECURE_AUTH_SALT', 'put your unique phrase here'); -define('LOGGED_IN_SALT', 'put your unique phrase here'); -define('NONCE_SALT', 'put your unique phrase here'); -define('FS_METHOD', 'direct'); - -/**#@-*/ - -/** - * WordPress Database Table prefix. - * - * You can have multiple installations in one database if you give each - * a unique prefix. Only numbers, letters, and underscores please! - */ -$table_prefix = 'wp_'; - -/** - * For developers: WordPress debugging mode. - * - * Change this to true to enable the display of notices during development. - * It is strongly recommended that plugin and theme developers use WP_DEBUG - * in their development environments. - * - * For information on other constants that can be used for debugging, - * visit the Codex. - * - * @link https://codex.wordpress.org/Debugging_in_WordPress - */ -define('WP_DEBUG', false); - -/* That's all, stop editing! Happy blogging. */ - -/** Absolute path to the WordPress directory. */ -if ( !defined('ABSPATH') ) - define('ABSPATH', dirname(__FILE__) . '/'); - -/** Sets up WordPress vars and included files. */ -require_once(ABSPATH . 'wp-settings.php'); +<?php +/** + * The base configuration for WordPress + * + * The wp-config.php creation script uses this file during the + * installation. You don't have to use the web site, you can + * copy this file to "wp-config.php" and fill in the values. + * + * This file contains the following configurations: + * + * * MySQL settings + * * Secret keys + * * Database table prefix + * * ABSPATH + * + * @link https://codex.wordpress.org/Editing_wp-config.php + * + * @package WordPress + */ + +// ** MySQL settings - You can get this info from your web host ** // +/** The name of the database for WordPress */ +define('DB_NAME', 'wordpress'); + +/** MySQL database username */ +define('DB_USER', 'wordpress'); + +/** MySQL database password */ +define('DB_PASSWORD', 'wordpress'); + +/** MySQL hostname */ +define('DB_HOST', 'localhost'); + +/** Database Charset to use in creating database tables. */ +define('DB_CHARSET', 'utf8'); + +/** The Database Collate type. Don't change this if in doubt. */ +define('DB_COLLATE', 'utf8_general_ci'); + +/**#@+ + * Authentication Unique Keys and Salts. + * + * Change these to different unique phrases! + * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service} + * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again. + * + * @since 2.6.0 + */ +define('AUTH_KEY', 'put your unique phrase here'); +define('SECURE_AUTH_KEY', 'put your unique phrase here'); +define('LOGGED_IN_KEY', 'put your unique phrase here'); +define('NONCE_KEY', 'put your unique phrase here'); +define('AUTH_SALT', 'put your unique phrase here'); +define('SECURE_AUTH_SALT', 'put your unique phrase here'); +define('LOGGED_IN_SALT', 'put your unique phrase here'); +define('NONCE_SALT', 'put your unique phrase here'); +define('FS_METHOD', 'direct'); +define('WP_HOME', '{{ fqdn }}'); +define('WP_SITEURL', '{{ fqdn }}'); +{% if force_ssl %} +$_SERVER['HTTPS']='on'; +{% endif %} + +/**#@-*/ + +/** + * WordPress Database Table prefix. + * + * You can have multiple installations in one database if you give each + * a unique prefix. Only numbers, letters, and underscores please! + */ +$table_prefix = 'wp_'; + +/** + * For developers: WordPress debugging mode. + * + * Change this to true to enable the display of notices during development. + * It is strongly recommended that plugin and theme developers use WP_DEBUG + * in their development environments. + * + * For information on other constants that can be used for debugging, + * visit the Codex. + * + * @link https://codex.wordpress.org/Debugging_in_WordPress + */ +define('WP_DEBUG', false); + +/* That's all, stop editing! Happy blogging. */ + +/** Absolute path to the WordPress directory. */ +if ( !defined('ABSPATH') ) + define('ABSPATH', dirname(__FILE__) . '/'); + +/** Sets up WordPress vars and included files. */ +require_once(ABSPATH . 'wp-settings.php'); -- GitLab