Skip to content
Snippets Groups Projects
Commit 8ac1585e authored by nimrod's avatar nimrod
Browse files

Pretty much finished the role.

parent 2e6e91a1
No related branches found
No related tags found
No related merge requests found
Role Name ansible-wordpress
========= =================
A brief description of the role goes here. Ansible role for installing Wordpress. It installs Nginx, PHP-FPM and MySQL
locally. Backups of the Wordpress database and directory are done (and saved for
7 days). Theme and plugin installation is done via the filesystem (no FTP
access).
Requirements 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. Debian Jessie.
Role Variables 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. None.
Dependencies 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. None.
Example Playbook 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 - hosts: servers
roles: roles:
- { role: username.rolename, x: 42 } - wordpress
License License
------- -------
BSD MIT
Author Information Author Information
------------------ ------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed). Nimrod Adar.
--- ---
# handlers file for wordpress # handlers file for wordpress
- name: Restart Nginx
service:
name: nginx
state: restarted
- name: Restart PHP-FPM
service:
name: php5-fpm
state: restarted
- name: Restart MySQL
service:
name: mysql
state: restarted
--- ---
galaxy_info: galaxy_info:
author: your name author: Nimrod Adar
description: description: Wordpress roles. For more information read the README file.
company: your company (optional) company: Shore technologies
# If the issue tracker for your role is not on github, uncomment the license: MIT
# 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 min_ansible_version: 1.2
# platforms:
# Below are all platforms currently available. Just uncomment - name: Debian
# the ones that apply to your role. If you don't see your versions:
# platform on this list, let us know and we'll get it added! - jessie
# categories:
#platforms: - web
#- name: EL
# versions:
# - all
# - 5
# - 6
# - 7
#- name: GenericUNIX
# versions:
# - all
# - any
#- name: Fedora
# versions:
# - all
# - 16
# - 17
# - 18
# - 19
# - 20
# - 21
# - 22
#- name: Windows
# versions:
# - all
# - 2012R2
#- name: SmartOS
# versions:
# - all
# - any
#- name: opensuse
# versions:
# - all
# - 12.1
# - 12.2
# - 12.3
# - 13.1
# - 13.2
#- name: Amazon
# versions:
# - all
# - 2013.03
# - 2013.09
#- name: GenericBSD
# versions:
# - all
# - any
#- name: FreeBSD
# versions:
# - all
# - 8.0
# - 8.1
# - 8.2
# - 8.3
# - 8.4
# - 9.0
# - 9.1
# - 9.1
# - 9.2
#- name: Ubuntu
# versions:
# - all
# - lucid
# - maverick
# - natty
# - oneiric
# - precise
# - quantal
# - raring
# - saucy
# - trusty
# - utopic
# - vivid
#- name: SLES
# versions:
# - all
# - 10SP3
# - 10SP4
# - 11
# - 11SP1
# - 11SP2
# - 11SP3
#- name: GenericLinux
# versions:
# - all
# - any
#- name: Debian
# versions:
# - all
# - etch
# - jessie
# - lenny
# - squeeze
# - wheezy
#
# Below are all categories currently available. Just as with
# the platforms above, uncomment those that apply to your role.
#
#categories:
#- cloud
#- cloud:ec2
#- cloud:gce
#- cloud:rax
#- clustering
#- database
#- database:nosql
#- database:sql
#- development
#- monitoring
#- networking
#- packaging
#- system
#- web
dependencies: [] dependencies: []
# List your role dependencies here, one per line.
# Be sure to remove the '[]' above if you add dependencies
# to this list.
--- ---
# tasks file for wordpress # tasks file for wordpress
- include: php.yml
- include: mysql.yml
- name: Get tarball
get_url:
url: 'https://wordpress.org/latest.tar.gz'
dest: /root/wordpress.tar.gz
owner: root
group: root
mode: '0644'
- name: Unpack tarball
unarchive:
copy: no
dest: /var/www
src: /root/wordpress.tar.gz
owner: root
group: root
mode: '0755'
creates: /var/www/wordpress/index.php
- name: Configure Wordpress
template:
src: wp-config.php.j2
dest: /var/www/wp-config.php
owner: root
group: root
mode: '0755'
- name: Make plugins, themes installable
file:
path: /var/www/wordpress/wp-content
owner: www-data
recurse: yes
state: directory
- name: Create backup destination
file:
path: /var/backups
state: directory
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: apt-get install mysql
apt:
name: '{{ item }}'
state: present
update_cache: yes
cache_valid_time: 3600
with_items:
- mysql-server
- mysql-client
- python-mysqldb
- 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
---
- 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
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/wordpress;
index index.html index.htm index.php;
server_name _;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
<?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');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment