Skip to content

Instantly share code, notes, and snippets.

@stefanotorresi
Created April 7, 2016 11:46
Show Gist options
  • Save stefanotorresi/4346108ebfc858cb80d02d580cddc65c to your computer and use it in GitHub Desktop.
Save stefanotorresi/4346108ebfc858cb80d02d580cddc65c to your computer and use it in GitHub Desktop.
Wordpress theme deployment and development with Ansible, Composer and wp-cli
---
- hosts: wordpress-server
vars:
root_directory: /var/www/html
theme_name: your-theme-name
theme_repo: https://yourtheme.git.url.git
locale: it_IT
url: http://absolute-url.tld
title: Worpdress
admin_user: admin
admin_pwd: admin
admin_email: email@tld.com
debug: true
mysql:
root_pwd: secret
db: wordpress
user: wordpress
pwd: another_secret
tasks:
- name: Install base packages
sudo: true
apt: pkg={{item}} state=latest
with_items:
- mysql-server
- mysql-client
- apache2
- php5
- php5-cli
- curl
- python-mysqldb
- git
- name: Ensure required services are running
sudo: true
service: name={{item}} state=started
with_items:
- apache2
- mysql
- name: Install Composer
sudo: true
shell: >
curl -sS https://getcomposer.org/installer | php
&& mv composer.phar /usr/local/bin/composer
creates=/usr/local/bin/composer
- name: Install WP-CLI
sudo: true
shell: >
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
&& mv wp-cli.phar /usr/local/bin/wp
creates=/usr/local/bin/wp
- name: Ensure WP-CLI permissions
sudo: true
file: path=/usr/local/bin/wp state=file mode=755
- name: Create Wordpress directory
sudo: true
file: path={{root_directory}} state=directory mode=777
- name: Download Wordpress
command: wp core download chdir={{root_directory}} creates={{root_directory}}/index.php
- name: Ensure wp-content is world writeable
sudo: true
file: path={{root_directory}}/wp-content state=directory mode=777 recurse=yes
- name: Ensure MySQL database is present
sudo: true
mysql_db: login_user=root login_password={{mysql.root_pwd}} name={{mysql.db}} state=present
- name: Ensure MySQL user is present
sudo: true
mysql_user: >
login_user=root login_password={{mysql.root_pwd}} name={{mysql.user}} password={{mysql.pwd}}
priv={{mysql.db}}.*:ALL state=present
- name: Create Worpress configuration
command: >
wp core config --dbname={{mysql.db}} --dbuser={{mysql.user}} --dbpass={{mysql.pwd}} --locale={{locale}}
chdir={{root_directory}} creates={{root_directory}}/wp-config.php
- name: Ensure FS_METHOD is set to direct
lineinfile: >
dest={{root_directory}}/wp-config.php line="define('FS_METHOD', 'direct');"
insertafter="^define\('WPLANG'"
state=present
- name: Set Wordpress debugging
lineinfile: >
dest={{root_directory}}/wp-config.php line="define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);"
insertafter="^define\('FS_METHOD'"
state=present
when: "{{ debug }}"
- name: Check if Wordpress is already installed
command: wp core is-installed chdir={{root_directory}}
register: wordpress_is_installed
- name: Install Wordpress
command: >
wp core install --url={{url}} --title="{{title}}" --admin_user={{admin_user}} --admin_password={{admin_pwd}}
--admin_email={{admin_email}} chdir={{root_directory}}
when: not wordpress_is_installed
- name: Install theme
git:
repo: "{{ theme_repo }}"
dest: "{{root_directory}}/wp-content/themes/{{theme_name}}"
- name: Activate theme
command: wp theme activate {{theme_name}} chdir={{root_directory}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment