├── .ansible-lint ├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .yamllint ├── Dockerfile ├── LICENSE.txt ├── README.md ├── Vagrantfile ├── defaults └── main.yml ├── files └── empty ├── handlers └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── collections.yml │ ├── converge.yml │ ├── molecule.yml │ ├── prepare.yml │ └── verify.yml ├── requirements.yml ├── tasks ├── chown.yml ├── configure.yml ├── core.yml ├── main.yml ├── options.yml ├── plugins.yml ├── queries.yml ├── themes.yml ├── users.yml ├── wp-cli.yml └── wp-cron.yml ├── templates └── empty ├── tests ├── handlers │ └── main.yml ├── inventory ├── tasks │ └── pre.yml ├── test.yml ├── vagrant.sh ├── vagrant.yml └── vars │ └── main.yml └── vars └── main.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | --- 2 | warn_list: 3 | - role-name 4 | - name[play] 5 | - name[casing] 6 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: '30 1 * * 3' 10 | 11 | jobs: 12 | 13 | lint: 14 | name: Lint 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Check out the codebase 18 | uses: actions/checkout@v3 19 | 20 | - name: Set up Python 3 21 | uses: actions/setup-python@v4 22 | with: 23 | python-version: '3.x' 24 | 25 | - name: Install test dependencies 26 | run: | 27 | pip install ansible-lint 28 | ansible-galaxy install -r requirements.yml 29 | 30 | - name: Lint code 31 | run: | 32 | yamllint . 33 | ansible-lint 34 | 35 | molecule: 36 | name: Molecule 37 | runs-on: ubuntu-latest 38 | defaults: 39 | run: 40 | working-directory: "${{ github.repository }}" 41 | needs: 42 | - lint 43 | strategy: 44 | fail-fast: false 45 | matrix: 46 | include: 47 | - distro: ubuntu1604 48 | ansible-version: '>=2.10, <2.11' 49 | - distro: ubuntu1604 50 | - distro: ubuntu1804 51 | - distro: ubuntu2004 52 | 53 | steps: 54 | - name: Check out the codebase 55 | uses: actions/checkout@v3 56 | with: 57 | path: "${{ github.repository }}" 58 | 59 | - name: Set up Python 3 60 | uses: actions/setup-python@v4 61 | with: 62 | python-version: '3.x' 63 | 64 | - name: Install test dependencies 65 | run: pip install 'ansible${{ matrix.ansible-version }}' molecule-plugins[docker] docker 66 | 67 | - name: Run Molecule tests 68 | run: | 69 | molecule test 70 | env: 71 | ANSIBLE_FORCE_COLOR: '1' 72 | ANSIBLE_VERBOSITY: '2' 73 | MOLECULE_DEBUG: '1' 74 | MOLECULE_DISTRO: "${{ matrix.distro }}" 75 | PY_COLORS: '1' 76 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 3 | 'on': 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | 10 | release: 11 | name: Release 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Check out the codebase 15 | uses: actions/checkout@v3 16 | 17 | - name: Publish to Galaxy 18 | uses: robertdebock/galaxy-action@1.2.0 19 | with: 20 | galaxy_api_key: ${{ secrets.GALAXY_API_KEY }} 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS generated files # 2 | ###################### 3 | .DS_Store 4 | .DS_Store? 5 | ._* 6 | .Spotlight-V100 7 | .Trashes 8 | Icon? 9 | ehthumbs.db 10 | Thumbs.db 11 | 12 | # IDE files # 13 | ################# 14 | /.settings 15 | /.buildpath 16 | /.project 17 | /nbproject 18 | *.komodoproject 19 | *.kpf 20 | /.idea 21 | 22 | # Vagrant files # 23 | .virtualbox/ 24 | .vagrant/ 25 | vagrant_ansible_inventory_* 26 | ansible.cfg 27 | 28 | # Other files # 29 | ############### 30 | !empty 31 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | braces: 6 | max-spaces-inside: 1 7 | level: error 8 | brackets: 9 | max-spaces-inside: 1 10 | level: error 11 | line-length: disable 12 | truthy: disable 13 | 14 | ignore: | 15 | .tox/ 16 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | MAINTAINER Mischa ter Smitten 3 | 4 | ENV LANG C.UTF-8 5 | ENV LC_ALL C.UTF-8 6 | 7 | # python 8 | RUN apt-get update && \ 9 | DEBIAN_FRONTEND=noninteractive apt-get install -y python3-minimal python3-dev curl && \ 10 | apt-get clean 11 | RUN curl -sL https://bootstrap.pypa.io/pip/3.6/get-pip.py | python3 - 12 | RUN rm -rf $HOME/.cache 13 | 14 | # ansible 15 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python3-apt && \ 16 | apt-get clean 17 | RUN pip3 install ansible==2.10.7 18 | RUN rm -rf $HOME/.cache 19 | 20 | # provision 21 | COPY . /etc/ansible/roles/ansible-role 22 | WORKDIR /etc/ansible/roles/ansible-role 23 | RUN ansible-playbook -i tests/inventory tests/test.yml --connection=local 24 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Oefenweb.nl 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## wordpress 2 | 3 | [![Build Status](https://travis-ci.org/Oefenweb/ansible-wordpress.svg?branch=master)](https://travis-ci.org/Oefenweb/ansible-wordpress) [![Ansible Galaxy](http://img.shields.io/badge/ansible--galaxy-wordpress-blue.svg)](https://galaxy.ansible.com/Oefenweb/wordpress) 4 | 5 | Set up (multiple) wordpress installations in Debian-like systems (using `wp-cli`). 6 | 7 | #### Requirements 8 | 9 | * `php` (5.3.2+) 10 | * `mysql` (5.0+) 11 | * `apache2` (with `mod_rewrite` enabled) 12 | 13 | This role assumes a working virtual host (that handles `wordpress_url`). 14 | 15 | #### Variables 16 | 17 | * `wordpress_wp_cli_install_dir` [default: `/usr/local/bin`]: Install directory for `wp-cli` 18 | 19 | * `wordpress_installs`: [default: `[]`]: Installation declarations 20 | * `wordpress_installs.{n}.name`: [required]: Install name (not used for anything, just an identifier) 21 | * `wordpress_installs.{n}.dbname`: [required]: Database name 22 | * `wordpress_installs.{n}.dbuser`: [required]: Database username 23 | * `wordpress_installs.{n}.dbpass`: [required]: Database password (**make sure to change**) 24 | * `wordpress_installs.{n}.dbhost`: [default: `localhost`, optional]: Database host 25 | * `wordpress_installs.{n}.dbprefix`: [default: `wp_`, optional]: Prefix for database tables 26 | * `wordpress_installs.{n}.path`: [required]: Install directory for wordpress 27 | * `wordpress_installs.{n}.locale`: [default: `en_US`, optional]: Language of the downloaded Wordpress 28 | * `wordpress_installs.{n}.owner`: [default: `www-data`]: The name of the user that should own the install 29 | * `wordpress_installs.{n}.group`: [default: `owner`, `www-data`]: The name of the group that should own the install 30 | * `wordpress_installs.{n}.url`: [required]: Wordpress url 31 | * `wordpress_installs.{n}.title`: [required]: Wordpress title 32 | * `wordpress_installs.{n}.admin_name`: [default: `admin`, optional]: Wordpress admin (user)name 33 | * `wordpress_installs.{n}.admin_email`: [required]: Wordpress admin email address 34 | * `wordpress_installs.{n}.admin_password`: [required]: Wordpress admin password (**make sure to change**) 35 | 36 | * `wordpress_installs.{n}.cron`: [optional]: Cron declaration 37 | * `wordpress_installs.{n}.cron.use_crond`: [default: `false`]: Whether or not to use `crond` instead of wp-cron 38 | * `wordpress_installs.{n}.cron.user`: [default: `www-data`]: User to run job as 39 | * `wordpress_installs.{n}.cron.schedule`: [optional]: Cron schedule declaration 40 | * `wordpress_installs.{n}.cron.schedule.day`: [default: `*`]: Day when the job should run 41 | * `wordpress_installs.{n}.cron.schedule.hour`: [default: `*`]: Hour when the job should run 42 | * `wordpress_installs.{n}.cron.schedule.minute`: [default: `*`]: Minute when the job should run 43 | * `wordpress_installs.{n}.cron.schedule.month`: [default: `*`]: Month when the job should run 44 | * `wordpress_installs.{n}.cron.schedule.weekday`: [default: `*`]: Weekday when the job should run 45 | 46 | * `wordpress_installs.{n}.themes`: [required]: (Additional) themes to install (and activate) 47 | * `wordpress_installs.{n}.themes.{n}.name`: [required]: Name of the theme 48 | * `wordpress_installs.{n}.themes.{n}.activate`: [default: `false`, optional]: Whether or not to activate the theme 49 | 50 | * `wordpress_installs.{n}.plugins`: [required]: (Additional) plugins to install (and activate) 51 | * `wordpress_installs.{n}.plugins.{n}.name`: [required]: Name of the plugin 52 | * `wordpress_installs.{n}.plugins.{n}.zip`: [optional]: Zip of the plugin 53 | * `wordpress_installs.{n}.plugins.{n}.url`: [optional]: Url of the plugin 54 | * `wordpress_installs.{n}.plugins.{n}.activate`: [default: `true`, optional]: Whether to activate or to deactivate the plugin 55 | * `wordpress_installs.{n}.plugins.{n}.force`: [default: `false`, optional]: Whether or not to add the `--force` option during install 56 | 57 | * `wordpress_installs.{n}.users`: [optional]: User declarations 58 | * `wordpress_installs.{n}.users.src`: [required]: The local path of the [csv file](http://wp-cli.org/commands/user/import-csv/) to import, can be absolute or relative (e.g. `../../../files/wordpress/users.csv`) 59 | * `wordpress_installs.{n}.users.skip_update`: [default: `true`, optional]: Whether or not to update users that already exist 60 | 61 | * `wordpress_installs.{n}.options`: [required]: Options to add, update or delete 62 | * `wordpress_installs.{n}.options.{n}.command`: [required]: Add, update or delete 63 | * `wordpress_installs.{n}.options.{n}.name`: [required]: Name of the option 64 | * `wordpress_installs.{n}.options.{n}.value`: [required]: Value of the option 65 | * `wordpress_installs.{n}.options.{n}.autoload`: [default: `true`, optional]: Whether this option should be automatically loaded (only supported for add command) 66 | 67 | * `wordpress_installs.{n}.queries`: [default: `[]`, optional]: A list of queries to execute 68 | 69 | ## Dependencies 70 | 71 | None 72 | 73 | ## Examples 74 | 75 | ### Quickstart 76 | 77 | ```yaml 78 | --- 79 | - hosts: all 80 | roles: 81 | - oefenweb.wordpress 82 | vars: 83 | wordpress_installs: 84 | - name: wordpress 85 | dbname: wordpress 86 | dbuser: wordpress 87 | dbpass: 'heCrE7*d2KEs' 88 | dbhost: localhost 89 | path: /var/www 90 | url: http://localhost 91 | title: wordpress 92 | admin_name: admin 93 | admin_email: root@localhost.localdomain 94 | admin_password: 'tuFr8=aPra@a' 95 | themes: 96 | - name: twentytwelve 97 | activate: true 98 | - name: twentythirteen 99 | plugins: 100 | - name: contact-form-7 101 | activate: false 102 | - name: simple-fields 103 | users: {} 104 | options: [] 105 | queries: [] 106 | ``` 107 | 108 | ### Using options: 109 | 110 | 111 | ```yaml 112 | --- 113 | - hosts: all 114 | roles: 115 | - oefenweb.wordpress 116 | vars: 117 | wordpress_installs: 118 | - name: wordpress 119 | dbname: wordpress 120 | dbuser: wordpress 121 | dbpass: 'heCrE7*d2KEs' 122 | dbhost: localhost 123 | path: /var/www 124 | url: http://localhost 125 | title: wordpress 126 | admin_name: admin 127 | admin_email: root@localhost.localdomain 128 | admin_password: 'tuFr8=aPra@a' 129 | themes: 130 | - name: twentytwelve 131 | activate: true 132 | - name: twentythirteen 133 | plugins: 134 | - name: contact-form-7 135 | activate: false 136 | - name: simple-fields 137 | users: {} 138 | options: 139 | - name: woocommerce_api_enabled 140 | command: update 141 | value: yes 142 | - name: swoocommerce_email_from_name 143 | command: update 144 | vakue: payments@mycompany.com 145 | - name: woocommerce_currency 146 | command: update 147 | vakue: MXN 148 | queries: [] 149 | ``` 150 | 151 | #### License 152 | 153 | MIT 154 | 155 | #### Author Information 156 | 157 | Mischa ter Smitten 158 | 159 | #### Feedback, bug-reports, requests, ... 160 | 161 | Are [welcome](https://github.com/Oefenweb/ansible-wordpress/issues)! 162 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby ts=2 sw=2 tw=0 et : 3 | 4 | role = File.basename(File.expand_path(File.dirname(__FILE__))) 5 | 6 | boxes = [ 7 | { 8 | :name => "ubuntu-1604", 9 | :box => "bento/ubuntu-16.04", 10 | :ip => '10.0.0.13', 11 | :cpu => "50", 12 | :ram => "256" 13 | }, 14 | { 15 | :name => "ubuntu-1804", 16 | :box => "bento/ubuntu-18.04", 17 | :ip => '10.0.0.14', 18 | :cpu => "50", 19 | :ram => "384" 20 | }, 21 | { 22 | :name => "ubuntu-2004", 23 | :box => "bento/ubuntu-20.04", 24 | :ip => '10.0.0.15', 25 | :cpu => "50", 26 | :ram => "384" 27 | }, 28 | ] 29 | 30 | Vagrant.configure("2") do |config| 31 | boxes.each do |box| 32 | config.vm.define box[:name] do |vms| 33 | vms.vm.box = box[:box] 34 | vms.vm.hostname = "ansible-#{role}-#{box[:name]}" 35 | 36 | vms.vm.provider "virtualbox" do |v| 37 | v.customize ["modifyvm", :id, "--cpuexecutioncap", box[:cpu]] 38 | v.customize ["modifyvm", :id, "--memory", box[:ram]] 39 | end 40 | 41 | vms.vm.network :private_network, ip: box[:ip] 42 | 43 | vms.vm.provision :ansible do |ansible| 44 | ansible.playbook = "tests/vagrant.yml" 45 | ansible.verbose = "vv" 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | # defaults file 2 | --- 3 | wordpress_wp_cli_install_dir: /usr/local/bin 4 | 5 | wordpress_installs: [] 6 | -------------------------------------------------------------------------------- /files/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oefenweb/ansible-wordpress/5e819f669fb75324860daad2908ef83285b5ba73/files/empty -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | # handlers file 2 | --- 3 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | # meta file 2 | --- 3 | galaxy_info: 4 | namespace: oefenweb 5 | role_name: wordpress 6 | author: Mischa ter Smitten 7 | company: Oefenweb.nl B.V. 8 | description: Set up (multiple) wordpress installations in Debian-like systems (using wp-cli) 9 | license: MIT 10 | min_ansible_version: 2.10.0 11 | platforms: 12 | - name: Ubuntu 13 | versions: 14 | - precise 15 | - trusty 16 | - xenial 17 | - bionic 18 | - name: Debian 19 | versions: 20 | - wheezy 21 | - jessie 22 | - stretch 23 | - buster 24 | galaxy_tags: 25 | - web 26 | dependencies: [] 27 | -------------------------------------------------------------------------------- /molecule/default/collections.yml: -------------------------------------------------------------------------------- 1 | --- 2 | collections: 3 | - name: community.docker 4 | version: '>=1.2.0,<2' 5 | - name: community.general 6 | version: '>=2,<3' 7 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | become: true 5 | pre_tasks: 6 | - name: include vars 7 | ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" 8 | roles: 9 | - ../../../ 10 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: galaxy 4 | driver: 5 | name: docker 6 | platforms: 7 | - name: instance 8 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu1604}-ansible:latest" 9 | command: ${MOLECULE_DOCKER_COMMAND:-""} 10 | volumes: 11 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 12 | - /var/lib/containerd 13 | cgroupns_mode: host 14 | privileged: true 15 | pre_build_image: true 16 | provisioner: 17 | name: ansible 18 | playbooks: 19 | prepare: prepare.yml 20 | converge: converge.yml 21 | verify: verify.yml 22 | -------------------------------------------------------------------------------- /molecule/default/prepare.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Prepare 3 | hosts: all 4 | become: true 5 | tasks: 6 | - name: include vars 7 | ansible.builtin.include_vars: "{{ playbook_dir }}/../../defaults/main.yml" 8 | - name: include vars 9 | ansible.builtin.include_vars: "{{ playbook_dir }}/../../tests/vars/main.yml" 10 | - name: include tasks 11 | ansible.builtin.import_tasks: "{{ playbook_dir }}/../../tests/tasks/pre.yml" 12 | handlers: 13 | - name: include handlers 14 | ansible.builtin.import_tasks: "{{ playbook_dir }}/../../tests/handlers/main.yml" 15 | -------------------------------------------------------------------------------- /molecule/default/verify.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Verify 3 | hosts: all 4 | become: true 5 | tasks: [] 6 | -------------------------------------------------------------------------------- /requirements.yml: -------------------------------------------------------------------------------- 1 | # requirements file 2 | --- 3 | collections: 4 | - name: community.mysql 5 | -------------------------------------------------------------------------------- /tasks/chown.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: change owner (and group) 4 | ansible.builtin.file: 5 | path: "{{ item.path }}" 6 | owner: "{{ item.owner | default('www-data') }}" 7 | group: "{{ item.group | default(item.owner) | default('www-data') }}" 8 | recurse: true 9 | with_items: "{{ wordpress_installs }}" 10 | -------------------------------------------------------------------------------- /tasks/configure.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: configure | create (data) directories 4 | ansible.builtin.file: 5 | path: "{{ item }}" 6 | state: directory 7 | owner: root 8 | group: root 9 | mode: 0755 10 | with_items: 11 | - "{{ wordpress_data_path }}/themes" 12 | - "{{ wordpress_data_path }}/plugins" 13 | - "{{ wordpress_data_path }}/users" 14 | tags: 15 | - wordpress-configure-create-data-directory 16 | -------------------------------------------------------------------------------- /tasks/core.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: core | check download 4 | ansible.builtin.command: > 5 | test -f {{ item.path }}/wp-load.php 6 | register: _check_download 7 | failed_when: false 8 | changed_when: false 9 | with_items: "{{ wordpress_installs }}" 10 | tags: 11 | - wordpress-core-is-downloaded 12 | 13 | - name: core | download 14 | ansible.builtin.command: > 15 | wp-cli core download 16 | --allow-root --no-color --path='{{ item.item.path }}' 17 | --locale='{{ item.item.locale | default('en_US') }}' 18 | changed_when: true 19 | with_items: "{{ _check_download.results | default([]) }}" 20 | when: item.rc != 0 21 | tags: 22 | - wordpress-core-downloaded 23 | 24 | - name: core | configure 25 | ansible.builtin.command: > 26 | wp-cli core config 27 | --allow-root --no-color --path='{{ item.path }}' 28 | --dbname='{{ item.dbname }}' 29 | --dbuser='{{ item.dbuser }}' 30 | --dbpass='{{ item.dbpass }}' 31 | --dbhost='{{ item.dbhost | default('localhost') }}' 32 | --dbprefix='{{ item.dbprefix | default('wp_') }}' 33 | args: 34 | creates: "{{ item.path }}/wp-config.php" 35 | with_items: "{{ wordpress_installs }}" 36 | tags: 37 | - wordpress-core-configure 38 | 39 | - name: core | identify installation 40 | ansible.builtin.command: > 41 | wp-cli core is-installed 42 | --allow-root --no-color --path='{{ item.path }}' 43 | register: _check_installation 44 | failed_when: false 45 | changed_when: false 46 | with_items: "{{ wordpress_installs }}" 47 | tags: 48 | - wordpress-core-is-installed 49 | 50 | - name: core | install 51 | ansible.builtin.command: > 52 | wp-cli core install 53 | --allow-root --no-color --path='{{ item.item.path }}' 54 | --url='{{ item.item.url }}' --title='{{ item.item.title }}' 55 | --admin_name='{{ item.item.admin_name | default('admin') }}' 56 | --admin_email='{{ item.item.admin_email }}' 57 | --admin_password='{{ item.item.admin_password }}' 58 | changed_when: true 59 | with_items: "{{ _check_installation.results | default([]) }}" 60 | when: item.rc != 0 61 | tags: 62 | - wordpress-core-install 63 | 64 | - name: core | check install 65 | ansible.builtin.command: > 66 | wp-cli core is-installed 67 | --allow-root --no-color --path='{{ item.path }}' 68 | changed_when: false 69 | with_items: "{{ wordpress_installs }}" 70 | tags: 71 | - wordpress-core-install-check 72 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: wp-cli 4 | ansible.builtin.import_tasks: wp-cli.yml 5 | tags: 6 | - configuration 7 | - wordpress 8 | - wordpress-wp-cli 9 | 10 | - name: core 11 | ansible.builtin.import_tasks: core.yml 12 | tags: 13 | - configuration 14 | - wordpress 15 | - wordpress-core 16 | 17 | - name: configure 18 | ansible.builtin.import_tasks: configure.yml 19 | tags: 20 | - configuration 21 | - wordpress 22 | - wordpress-configure 23 | 24 | - name: wp-cron 25 | ansible.builtin.import_tasks: wp-cron.yml 26 | tags: 27 | - configuration 28 | - wordpress 29 | - wordpress-wp-cron 30 | 31 | - name: themes 32 | ansible.builtin.import_tasks: themes.yml 33 | tags: 34 | - configuration 35 | - wordpress 36 | - wordpress-themes 37 | 38 | - name: plugins 39 | ansible.builtin.import_tasks: plugins.yml 40 | tags: 41 | - configuration 42 | - wordpress 43 | - wordpress-plugins 44 | 45 | - name: users 46 | ansible.builtin.import_tasks: users.yml 47 | tags: 48 | - configuration 49 | - wordpress 50 | - wordpress-users 51 | 52 | - name: options 53 | ansible.builtin.import_tasks: options.yml 54 | tags: 55 | - configuration 56 | - wordpress 57 | - wordpress-options 58 | 59 | - name: queries 60 | ansible.builtin.import_tasks: queries.yml 61 | tags: 62 | - configuration 63 | - wordpress 64 | - wordpress-queries 65 | 66 | - name: chown 67 | ansible.builtin.import_tasks: chown.yml 68 | tags: 69 | - configuration 70 | - wordpress 71 | - wordpress-chown 72 | -------------------------------------------------------------------------------- /tasks/options.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: add options 4 | ansible.builtin.command: > 5 | wp-cli option 6 | --allow-root --no-color --path='{{ item.0.path }}' 7 | {{ item.1.command }} '{{ item.1.name }}' '{{ item.1.value }}' --autoload={{ 'yes' if item.1.autoload | default(true) else 'no' }} 8 | register: _check_installation_options 9 | failed_when: false 10 | changed_when: "'Added' in _check_installation_options.stdout" 11 | with_subelements: 12 | - "{{ wordpress_installs }}" 13 | - options 14 | when: item.1.command == 'add' 15 | tags: 16 | - wordpress-options-add 17 | 18 | - name: update options 19 | ansible.builtin.command: > 20 | wp-cli option 21 | --allow-root --no-color --path='{{ item.0.path }}' 22 | {{ item.1.command }} '{{ item.1.name }}' '{{ item.1.value }}' 23 | register: _check_installation_options 24 | changed_when: "'unchanged' not in _check_installation_options.stdout" 25 | with_subelements: 26 | - "{{ wordpress_installs }}" 27 | - options 28 | when: item.1.command == 'update' 29 | tags: 30 | - wordpress-options-update 31 | 32 | - name: delete options 33 | ansible.builtin.command: > 34 | wp-cli option 35 | --allow-root --no-color --path='{{ item.0.path }}' 36 | {{ item.1.command }} '{{ item.1.name }}' 37 | register: _check_installation_options 38 | failed_when: false 39 | changed_when: "'Could not delete' not in _check_installation_options.stderr" 40 | with_subelements: 41 | - "{{ wordpress_installs }}" 42 | - options 43 | when: item.1.command == 'delete' 44 | tags: 45 | - wordpress-options-delete 46 | -------------------------------------------------------------------------------- /tasks/plugins.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: plugins | identify installation 4 | ansible.builtin.command: > 5 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin is-installed {{ item.1.name }} 6 | register: _check_installation_plugins 7 | failed_when: false 8 | changed_when: false 9 | with_subelements: 10 | - "{{ wordpress_installs }}" 11 | - plugins 12 | when: item.1 13 | tags: 14 | - wordpress-plugins-is-installed-plugin 15 | 16 | - name: plugins | install | wordpress.org 17 | ansible.builtin.command: > 18 | wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' 19 | {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.name }} 20 | changed_when: true 21 | with_items: "{{ _check_installation_plugins.results | default([]) }}" 22 | when: 23 | - item.item.1.name 24 | - not item.item.1.zip | default(false) 25 | - not item.item.1.url | default(false) 26 | - item.rc != 0 27 | tags: 28 | - wordpress-plugins-install-plugin 29 | - wordpress-plugins-install-plugin-wordpress_org 30 | 31 | - name: plugins | install | zip | copy 32 | ansible.builtin.copy: 33 | src: "{{ item.item.1.zip }}" 34 | dest: "{{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip" 35 | owner: root 36 | group: root 37 | mode: 0644 38 | with_items: "{{ _check_installation_plugins.results | default([]) }}" 39 | when: 40 | - item.item.1.name 41 | - item.item.1.zip | default(false) 42 | - not item.item.1.url | default(false) 43 | - item.rc != 0 44 | tags: 45 | - wordpress-plugins-install-plugin 46 | - wordpress-plugins-install-plugin-zip 47 | - wordpress-plugins-install-plugin-zip-copy 48 | 49 | - name: plugins | install | zip | install 50 | ansible.builtin.command: > 51 | wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' 52 | {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip 53 | changed_when: true 54 | with_items: "{{ _check_installation_plugins.results | default([]) }}" 55 | when: 56 | - item.item.1.name 57 | - item.item.1.zip | default(false) 58 | - not item.item.1.url | default(false) 59 | - item.rc != 0 60 | tags: 61 | - wordpress-plugins-install-plugin 62 | - wordpress-plugins-install-plugin-zip 63 | - wordpress-plugins-install-plugin-zip-install 64 | 65 | - name: plugins | install | url 66 | ansible.builtin.command: > 67 | wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' 68 | {{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.url }} 69 | changed_when: true 70 | with_items: "{{ _check_installation_plugins.results | default([]) }}" 71 | when: 72 | - item.item.1.name 73 | - not item.item.1.zip | default(false) 74 | - item.item.1.url | default(false) 75 | - item.rc != 0 76 | tags: 77 | - wordpress-plugins-install-plugin 78 | - wordpress-plugins-install-plugin-url 79 | 80 | - name: plugins | check install 81 | ansible.builtin.command: > 82 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin is-installed {{ item.1.name }} 83 | changed_when: false 84 | with_subelements: 85 | - "{{ wordpress_installs }}" 86 | - plugins 87 | when: item.1.name 88 | tags: 89 | - wordpress-plugins-check-install-plugin 90 | 91 | - name: plugins | activate 92 | ansible.builtin.command: > 93 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin activate {{ item.1.name }} 94 | register: _check_activate_plugin 95 | changed_when: "'Success: Plugin' in _check_activate_plugin.stdout and not 'already' in _check_activate_plugin.stdout" 96 | with_subelements: 97 | - "{{ wordpress_installs }}" 98 | - plugins 99 | when: 100 | - item.1.name 101 | - item.1.activate | default(true) 102 | tags: 103 | - wordpress-plugins-activate-plugin 104 | 105 | - name: plugins | deactivate 106 | ansible.builtin.command: > 107 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' plugin deactivate {{ item.1.name }} 108 | register: _check_deactivate_plugin 109 | changed_when: "'Success: Plugin' in _check_deactivate_plugin.stdout and not 'already' in _check_deactivate_plugin.stdout" 110 | with_subelements: 111 | - "{{ wordpress_installs }}" 112 | - plugins 113 | when: 114 | - item.1.name 115 | - not item.1.activate | default(true) 116 | tags: 117 | - wordpress-plugins-deactivate-plugin 118 | -------------------------------------------------------------------------------- /tasks/queries.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: queries | execute queries 4 | ansible.builtin.command: > 5 | wp-cli db query 6 | --allow-root --no-color --path='{{ item.0.path }}' 7 | "{{ item.1 }}; SELECT ROW_COUNT();" 8 | register: _check_execution_queries 9 | changed_when: "_check_execution_queries.stdout_lines[-1] | int > 0" 10 | with_subelements: 11 | - "{{ wordpress_installs | selectattr('queries', 'defined') | list }}" 12 | - queries 13 | tags: 14 | - wordpress-queries-execute-queries 15 | -------------------------------------------------------------------------------- /tasks/themes.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: themes | identify installation 4 | ansible.builtin.command: > 5 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme is-installed {{ item.1.name }} 6 | register: _check_installation_themes 7 | failed_when: false 8 | changed_when: false 9 | with_subelements: 10 | - "{{ wordpress_installs }}" 11 | - themes 12 | when: item.1.name 13 | tags: 14 | - wordpress-themes-is-installed-theme 15 | 16 | - name: themes | install 17 | ansible.builtin.command: > 18 | wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' theme install {{ item.item.1.name }} 19 | changed_when: true 20 | with_items: "{{ _check_installation_themes.results | default([]) }}" 21 | when: 22 | - item.item.1.name 23 | - item.rc != 0 24 | tags: 25 | - wordpress-themes-install-theme 26 | 27 | - name: themes | check install 28 | ansible.builtin.command: > 29 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme is-installed {{ item.1.name }} 30 | changed_when: false 31 | with_subelements: 32 | - "{{ wordpress_installs }}" 33 | - themes 34 | when: item.1.name 35 | tags: 36 | - wordpress-themes-install-theme-check 37 | 38 | - name: themes | activate 39 | ansible.builtin.command: > 40 | wp-cli --allow-root --no-color --path='{{ item.0.path }}' theme activate {{ item.1.name }} 41 | register: _check_activate_theme 42 | changed_when: "'Success: Switched to' in _check_activate_theme.stdout" 43 | with_subelements: 44 | - "{{ wordpress_installs }}" 45 | - themes 46 | when: 47 | - item.1.name 48 | - item.1.activate | default(false) 49 | tags: 50 | - wordpress-themes-activate-theme 51 | -------------------------------------------------------------------------------- /tasks/users.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: users | copy file 4 | ansible.builtin.copy: 5 | src: "{{ item.users.src }}" 6 | dest: "{{ wordpress_data_path }}/users/{{ item.dbname }}.csv" 7 | owner: root 8 | group: root 9 | mode: 0644 10 | register: _check_copy_users 11 | with_items: "{{ wordpress_installs }}" 12 | when: item.users.src is defined 13 | tags: 14 | - wordpress-users-copy-file 15 | 16 | - name: users | install # noqa no-handler 17 | ansible.builtin.command: > 18 | wp-cli user import-csv 19 | --allow-root --no-color --path='{{ item.item.path }}' 20 | {{ wordpress_data_path }}/users/{{ item.item.dbname }}.csv 21 | {{ '--skip-update' if item.item.users.skip_update | default(true) else '' }} 22 | --send-email 23 | register: _check_installation_users 24 | changed_when: "'Success' in _check_installation_users.stdout" 25 | with_items: "{{ _check_copy_users.results | default([]) }}" 26 | when: item.changed 27 | tags: 28 | - wordpress-users-import-file 29 | -------------------------------------------------------------------------------- /tasks/wp-cli.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: wp-cli | install 4 | ansible.builtin.get_url: 5 | url: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar 6 | dest: "{{ wordpress_wp_cli_install_dir }}/wp-cli" 7 | force: true 8 | owner: root 9 | group: root 10 | mode: 0755 11 | tags: 12 | - wordpress-wp-cli-install 13 | 14 | - name: wp-cli | check 15 | ansible.builtin.command: > 16 | wp-cli --allow-root --no-color --info 17 | register: _check_info 18 | failed_when: "'WP-CLI' not in _check_info.stdout" 19 | changed_when: false 20 | tags: 21 | - wordpress-wp-cli-check 22 | -------------------------------------------------------------------------------- /tasks/wp-cron.yml: -------------------------------------------------------------------------------- 1 | # tasks file 2 | --- 3 | - name: wp-cron | disable wp-cron 4 | ansible.builtin.lineinfile: 5 | dest: "{{ item.path }}/wp-config.php" 6 | line: "{{ wordpress_disable_wp_cron_line }}" 7 | insertafter: '^\<\?php' 8 | state: present 9 | with_items: "{{ wordpress_installs }}" 10 | when: 11 | - item.cron is defined 12 | - item.cron.use_crond | default(false) 13 | tags: 14 | - wordpress-wp-cron-disable-wp-cron 15 | 16 | - name: wp-cron | enable wp-cron 17 | ansible.builtin.lineinfile: 18 | dest: "{{ item.path }}/wp-config.php" 19 | line: "{{ wordpress_disable_wp_cron_line }}" 20 | state: absent 21 | with_items: "{{ wordpress_installs }}" 22 | when: item.cron is undefined or not item.cron.use_crond | default(false) 23 | tags: 24 | - wordpress-wp-cron-enable-wp-cron 25 | 26 | - name: wp-cron | enable crond 27 | ansible.builtin.cron: 28 | name: "{{ item.name }}" 29 | state: "{{ 'present' if item.cron is defined and item.cron.use_crond | default(false) else 'absent' }}" 30 | job: "wget -O /dev/null {{ item.url }}/wp-cron.php > /dev/null 2>&1" 31 | day: "{{ item.cron.schedule.day if item.cron is defined and item.cron.schedule is defined and item.cron.schedule.day is defined else '*' }}" 32 | hour: "{{ item.cron.schedule.hour if item.cron is defined and item.cron.schedule is defined and item.cron.schedule.hour is defined else '*' }}" 33 | minute: "{{ item.cron.schedule.minute if item.cron is defined and item.cron.schedule is defined and item.cron.schedule.minute is defined else '*' }}" 34 | month: "{{ item.cron.schedule.month if item.cron is defined and item.cron.schedule is defined and item.cron.schedule.month is defined else '*' }}" 35 | weekday: "{{ item.cron.schedule.weekday if item.cron is defined and item.cron.schedule is defined and item.cron.schedule.weekday is defined else '*' }}" 36 | cron_file: wp-cron 37 | user: "{{ item.cron.user if item.cron is defined and item.cron.user is defined else 'www-data' }}" 38 | with_items: "{{ wordpress_installs }}" 39 | tags: 40 | - wordpress-wp-cron-enable-crond 41 | -------------------------------------------------------------------------------- /templates/empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Oefenweb/ansible-wordpress/5e819f669fb75324860daad2908ef83285b5ba73/templates/empty -------------------------------------------------------------------------------- /tests/handlers/main.yml: -------------------------------------------------------------------------------- 1 | # handlers file 2 | --- 3 | - name: restart apache2 4 | ansible.builtin.service: 5 | name: apache2 6 | state: restarted 7 | 8 | - name: reload apache2 9 | ansible.builtin.service: 10 | name: apache2 11 | state: reloaded 12 | 13 | - name: restart mysql 14 | ansible.builtin.service: 15 | name: mysql 16 | state: restarted 17 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost 2 | -------------------------------------------------------------------------------- /tests/tasks/pre.yml: -------------------------------------------------------------------------------- 1 | # pre test file 2 | --- 3 | - name: percona server | add repo | dependencies 4 | ansible.builtin.apt: 5 | name: 6 | - software-properties-common 7 | - dirmngr 8 | update_cache: true 9 | cache_valid_time: "{{ apt_update_cache_valid_time | default(3600) }}" 10 | 11 | - name: percona server | add repo 12 | ansible.builtin.apt: 13 | deb: "https://repo.percona.com/apt/percona-release_latest.{{ ansible_distribution_release }}_all.deb" 14 | 15 | - name: php | add repo 16 | ansible.builtin.apt_repository: 17 | repo: 'ppa:ondrej/php' 18 | update_cache: true 19 | mode: 0644 20 | 21 | - name: percona server | preseed 22 | ansible.builtin.debconf: 23 | name: "{{ item.name }}" 24 | question: "{{ item.question }}" 25 | value: "{{ item.value }}" 26 | vtype: "{{ item.vtype }}" 27 | with_items: 28 | - name: "percona-server-server-5.7" 29 | question: "percona-server-server-5.7/root-pass" 30 | value: "{{ wordpress_percona_server_root_password }}" 31 | vtype: password 32 | - name: "percona-server-server-5.7" 33 | question: "percona-server-server-5.7/re-root-pass" 34 | value: "{{ wordpress_percona_server_root_password }}" 35 | vtype: password 36 | changed_when: false 37 | 38 | - name: percona server | install 39 | ansible.builtin.apt: 40 | name: 41 | - percona-server-client-5.7 42 | - percona-server-server-5.7 43 | - libperconaserverclient20 44 | - "python{{ ansible_python_version is version('3', '>=') | ternary('3', '') }}-mysqldb" 45 | state: "{{ apt_install_state | default('latest') }}" 46 | 47 | - name: php | install 48 | ansible.builtin.apt: 49 | name: 50 | - apache2 51 | - libapache2-mod-php7.4 52 | - php7.4-cli 53 | - php7.4-gd 54 | - php7.4-gmp 55 | - php7.4-json 56 | - php7.4-ldap 57 | - php7.4-mbstring 58 | - php7.4-mysql 59 | - php7.4-opcache 60 | - php7.4-snmp 61 | - php7.4-xml 62 | state: "{{ apt_install_state | default('latest') }}" 63 | 64 | - name: percona server | start 65 | ansible.builtin.service: 66 | name: mysql 67 | state: started 68 | 69 | - name: percona server | configure 70 | ansible.builtin.copy: 71 | dest: '~root/.my.cnf' 72 | content: | 73 | [client] 74 | host = localhost 75 | port = 3306 76 | user = root 77 | password = '{{ wordpress_percona_server_root_password }}' 78 | owner: root 79 | group: root 80 | mode: 0600 81 | 82 | - name: percona server | ensure database 83 | community.mysql.mysql_db: 84 | name: wordpress 85 | encoding: utf8mb4 86 | collation: utf8mb4_unicode_ci 87 | 88 | - name: percona server | ensure grants 89 | community.mysql.mysql_user: 90 | name: wordpress 91 | password: 'heCrE7*d2KEs' 92 | priv: 'wordpress.*:ALL' 93 | 94 | - name: apache server | start 95 | ansible.builtin.service: 96 | name: apache2 97 | state: started 98 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | # test file 2 | --- 3 | - hosts: localhost 4 | connection: local 5 | become: true 6 | pre_tasks: 7 | - name: include vars 8 | ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" 9 | - name: include tasks 10 | ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/pre.yml" 11 | roles: 12 | - ../../ 13 | handlers: 14 | - name: include handlers 15 | ansible.builtin.import_tasks: "{{ playbook_dir }}/handlers/main.yml" 16 | -------------------------------------------------------------------------------- /tests/vagrant.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # set -x; 4 | set -e; 5 | set -o pipefail; 6 | # 7 | thisFile="$(readlink -f ${0})"; 8 | thisFilePath="$(dirname ${thisFile})"; 9 | 10 | # Only provision once 11 | if [ -f /provisioned ]; then 12 | exit 0; 13 | fi 14 | 15 | export DEBIAN_FRONTEND=noninteractive; 16 | 17 | shopt -s expand_aliases; 18 | alias apt-update='apt-get update -qq'; 19 | alias apt-install='apt-get install -q -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'; 20 | 21 | apt-update; 22 | apt-install debconf-utils; 23 | 24 | echo 'mysql-server mysql-server/root_password password vagrant' | debconf-set-selections; 25 | echo 'mysql-server mysql-server/root_password_again password vagrant' | debconf-set-selections; 26 | echo 'mysql-server-5.1 mysql-server/root_password password vagrant' | debconf-set-selections; 27 | echo 'mysql-server-5.1 mysql-server/root_password_again password vagrant' | debconf-set-selections; 28 | echo 'mysql-server-5.5 mysql-server/root_password password vagrant' | debconf-set-selections; 29 | echo 'mysql-server-5.5 mysql-server/root_password_again password vagrant' | debconf-set-selections; 30 | echo 'mysql-server-5.6 mysql-server/root_password password vagrant' | debconf-set-selections; 31 | echo 'mysql-server-5.6 mysql-server/root_password_again password vagrant' | debconf-set-selections; 32 | 33 | apt-install mysql-server; 34 | 35 | cat << EOF > ~/.my.cnf 36 | [client] 37 | host = 127.0.0.1 38 | user = root 39 | password = vagrant 40 | EOF 41 | 42 | # No .my.cnf needed for Debian 9 (MariaDB) 43 | if $(lsb_release -c | grep -qE '(stretch)'); then 44 | rm ~/.my.cnf; 45 | fi 46 | 47 | # No PHP 5 support in Ubuntu 16.04 and Debian 9 48 | if $(lsb_release -c | grep -qE '(xenial|stretch)'); then 49 | PHP_VERSION='7.0'; 50 | else 51 | PHP_VERSION='5'; 52 | fi 53 | apt-install wget apache2 "php${PHP_VERSION}" "php${PHP_VERSION}-cli" "php${PHP_VERSION}-mysql" "libapache2-mod-php${PHP_VERSION}"; 54 | 55 | # Remove default index page of Ubuntu 1(0|2).04 / Debian (6|7) 56 | if [ -f /var/www/index.html ]; then 57 | rm -f /var/www/index.html; 58 | fi 59 | # Fix default document root of Ubuntu 14.04 60 | if [ -f /etc/apache2/sites-available/000-default.conf ]; then 61 | sed -i 's|/var/www/html|/var/www|g' /etc/apache2/sites-available/000-default.conf; 62 | fi 63 | 64 | a2enmod rewrite; 65 | service apache2 reload; 66 | 67 | # Fix missing sendmail 68 | ln -s -f /bin/true /usr/sbin/sendmail; 69 | 70 | mysql -e "CREATE DATABASE IF NOT EXISTS wordpress;"; 71 | mysql -e "CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'heCrE7*d2KEs';"; 72 | mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'wordpress'@'localhost' WITH GRANT OPTION;"; 73 | 74 | touch /provisioned; 75 | -------------------------------------------------------------------------------- /tests/vagrant.yml: -------------------------------------------------------------------------------- 1 | # test file 2 | --- 3 | - hosts: all 4 | remote_user: vagrant 5 | become: true 6 | pre_tasks: 7 | - name: include vars 8 | ansible.builtin.include_vars: "{{ playbook_dir }}/vars/main.yml" 9 | - name: include tasks 10 | ansible.builtin.import_tasks: "{{ playbook_dir }}/tasks/pre.yml" 11 | roles: 12 | - ../../ 13 | handlers: 14 | - name: include handlers 15 | ansible.builtin.import_tasks: "{{ playbook_dir }}/handlers/main.yml" 16 | vars: 17 | wordpress_installs: 18 | - name: wordpress 19 | dbname: wordpress 20 | dbuser: wordpress 21 | dbpass: 'heCrE7*d2KEs' 22 | dbhost: localhost 23 | path: /var/www 24 | url: "http://{{ hostvars[inventory_hostname]['ansible_' + (ansible_interfaces | difference(['lo']) | sort | list | last)]['ipv4']['address'] }}" 25 | title: wordpress 26 | admin_name: admin 27 | admin_email: root@localhost.localdomain 28 | admin_password: 'tuFr8=aPra@a' 29 | themes: 30 | - name: twentytwelve 31 | activate: true 32 | - name: twentythirteen 33 | plugins: 34 | - name: contact-form-7 35 | activate: false 36 | - name: wp-maintenance-mode 37 | - name: advanced-custom-fields-pro 38 | # zip: ../../../files/wordpress/plugins/advanced-custom-fields-pro.zip 39 | zip: "{{ playbook_dir }}/../files/advanced-custom-fields-pro.zip" 40 | - name: gravityforms 41 | # zip: ../../../files/wordpress/plugins/gravityforms.zip 42 | zip: "{{ playbook_dir }}/../files/gravityforms.zip" 43 | - name: envato-market 44 | url: https://envato.github.io/wp-envato-market/dist/envato-market.zip 45 | users: {} 46 | options: 47 | - command: add 48 | name: test 49 | value: 'not existing' 50 | autoload: false 51 | - command: add 52 | name: test 53 | value: 'existing' 54 | - command: update 55 | name: test 56 | value: 'existing' 57 | - command: update 58 | name: testtest 59 | value: 'not existing' 60 | - command: delete 61 | name: recently_edited 62 | value: 'existing' 63 | - command: delete 64 | name: testtesttest 65 | value: 'not existing' 66 | queries: 67 | - "UPDATE wp_options SET option_value = 0 WHERE option_name = 'comments_notify'" 68 | - "INSERT IGNORE INTO wp_options (option_name, option_value) VALUES ('mainwp_child_uniqueId', 'key')" 69 | -------------------------------------------------------------------------------- /tests/vars/main.yml: -------------------------------------------------------------------------------- 1 | # vars file 2 | --- 3 | wordpress_percona_server_root_password: root 4 | 5 | wordpress_installs: 6 | - name: wordpress 7 | dbname: wordpress 8 | dbuser: wordpress 9 | dbpass: 'heCrE7*d2KEs' 10 | dbhost: localhost 11 | path: /var/www 12 | url: http://localhost 13 | title: wordpress 14 | admin_name: admin 15 | admin_email: root@localhost.localdomain 16 | admin_password: 'tuFr8=aPra@a' 17 | cron: 18 | use_crond: true 19 | themes: 20 | - name: twentytwelve 21 | activate: true 22 | - name: twentythirteen 23 | plugins: 24 | - name: contact-form-7 25 | activate: false 26 | - name: acf-extended 27 | users: {} 28 | options: 29 | - command: add 30 | name: test 31 | value: 'not existing' 32 | - command: add 33 | name: test 34 | value: 'existing' 35 | - command: update 36 | name: test 37 | value: 'existing' 38 | - command: update 39 | name: testtest 40 | value: 'not existing' 41 | - command: delete 42 | name: recently_edited 43 | value: 'existing' 44 | - command: delete 45 | name: testtesttest 46 | value: 'not existing' 47 | queries: 48 | - "UPDATE wp_options SET option_value = 0 WHERE option_name = 'comments_notify'" 49 | - "INSERT IGNORE INTO wp_options (option_name, option_value) VALUES ('mainwp_child_uniqueId', 'key')" 50 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | # vars file 2 | --- 3 | wordpress_data_path: /var/lib/ansible/wordpress 4 | wordpress_disable_wp_cron_line: "define('DISABLE_WP_CRON', true);" 5 | --------------------------------------------------------------------------------