Skip to content

Commit

Permalink
Merge pull request #54 from Oefenweb/make-it-possible-to-install-plug…
Browse files Browse the repository at this point in the history
…ins-from-zip-and-url

Make it possible to install plugins from zip and url
  • Loading branch information
tersmitten authored Oct 25, 2017
2 parents 06c7041 + 6f3b471 commit 27d03cf
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 17 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:16.04
MAINTAINER Mischa ter Smitten <[email protected]>

# python
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y python-minimal python-dev curl && \
apt-get clean
RUN curl -sL https://bootstrap.pypa.io/get-pip.py | python -
RUN rm -rf $HOME/.cache

# ansible
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gcc libffi-dev libssl-dev && \
apt-get clean
RUN pip install ansible==2.3.2.0
RUN rm -rf $HOME/.cache

# provision
COPY . /etc/ansible/roles/ansible-role
WORKDIR /etc/ansible/roles/ansible-role
RUN ansible-playbook -i tests/inventory tests/test.yml --connection=local
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ This role assumes a working virtual host (that handles `wordpress_url`).
* `wordpress_installs.{n}.admin_name`: [default: `admin`, optional]: Wordpress admin (user)name
* `wordpress_installs.{n}.admin_email`: [required]: Wordpress admin email address
* `wordpress_installs.{n}.admin_password`: [required]: Wordpress admin password (**make sure to change**)

* `wordpress_installs.{n}.cron`: [optional]: Cron declaration
* `wordpress_installs.{n}.cron.use_crond`: [default: `false`]: Whether or not to use `crond` instead of wp-cron
* `wordpress_installs.{n}.cron.user`: [default: `www-data`]: User to run job as
Expand All @@ -41,20 +42,28 @@ This role assumes a working virtual host (that handles `wordpress_url`).
* `wordpress_installs.{n}.cron.schedule.minute`: [default: `*`]: Minute when the job should run
* `wordpress_installs.{n}.cron.schedule.month`: [default: `*`]: Month when the job should run
* `wordpress_installs.{n}.cron.schedule.weekday`: [default: `*`]: Weekday when the job should run

* `wordpress_installs.{n}.themes`: [required]: (Additional) themes to install (and activate)
* `wordpress_installs.{n}.themes.{n}.name`: [required]: Name of the theme
* `wordpress_installs.{n}.themes.{n}.activate`: [default: `false`, optional]: Whether or not to activate the theme

* `wordpress_installs.{n}.plugins`: [required]: (Additional) plugins to install (and activate)
* `wordpress_installs.{n}.plugins.{n}.name`: [required]: Name of the plugin
* `wordpress_installs.{n}.plugins.{n}.zip`: [optional]: Zip of the plugin
* `wordpress_installs.{n}.plugins.{n}.url`: [optional]: Url of the plugin
* `wordpress_installs.{n}.plugins.{n}.activate`: [default: `true`, optional]: Whether to activate or to deactivate the plugin
* `wordpress_installs.{n}.plugins.{n}.force`: [default: `false`, optional]: Whether or not to add the `--force` option during install

* `wordpress_installs.{n}.users`: [optional]: User declarations
* `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`)
* `wordpress_installs.{n}.users.skip_update`: [default: `true`, optional]: Whether or not to update users that already exist

* `wordpress_installs.{n}.options`: [required]: Options to add, update or delete
* `wordpress_installs.{n}.options.{n}.command`: [required]: Add, update or delete
* `wordpress_installs.{n}.options.{n}.name`: [required]: Name of the option
* `wordpress_installs.{n}.options.{n}.value`: [required]: Value of the option
* `wordpress_installs.{n}.options.{n}.autoload`: [default: `true`, optional]: Whether this option should be automatically loaded (only supported for add command)

* `wordpress_installs.{n}.queries`: [default: `[]`, optional]: A list of queries to execute

## Dependencies
Expand Down
7 changes: 7 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ boxes = [
:cpu => "50",
:ram => "256"
},
{
:name => "debian-9",
:box => "bento/debian-9",
:ip => '10.0.0.16',
:cpu => "50",
:ram => "256"
},
]

Vagrant.configure("2") do |config|
Expand Down
1 change: 1 addition & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ galaxy_info:
versions:
- wheezy
- jessie
- stretch
galaxy_tags:
- web
dependencies: []
15 changes: 15 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# tasks file for wordpress, configure
---
- name: configure | create (data) directories
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: 0755
with_items:
- "{{ wordpress_data_path }}/themes"
- "{{ wordpress_data_path }}/plugins"
- "{{ wordpress_data_path }}/users"
tags:
- wordpress-configure-create-data-directory
6 changes: 6 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
- wordpress
- wordpress-core

- include: configure.yml
tags:
- configuration
- wordpress
- wordpress-configure

- include: wp-cron.yml
tags:
- configuration
Expand Down
59 changes: 56 additions & 3 deletions tasks/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,66 @@
tags:
- wordpress-plugins-is-installed-plugin

- name: plugins | install
- name: plugins | install | wordpress.org
command: >
wp-cli --allow-root --no-color --path='{{ item.item.0.path }}' plugin install {{ item.item.1.name }}
wp-cli --allow-root --no-color --path='{{ item.item.0.path }}'
{{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.name }}
with_items: "{{ _check_installation_plugins.results | default([]) }}"
when: item.item.1.name and item.rc != 0
when: >
item.item.1.name
and item.item.1.zip | default('') == ''
and item.item.1.url | default('') == ''
and item.rc != 0
tags:
- wordpress-plugins-install-plugin
- wordpress-plugins-install-plugin-wordpress_org

- name: plugins | install | zip | copy
copy:
src: "{{ item.item.1.zip }}"
dest: "{{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip"
owner: root
group: root
mode: 0644
with_items: "{{ _check_installation_plugins.results | default([]) }}"
when: >
item.item.1.name
and item.item.1.zip | default('') != ''
and item.item.1.url | default('') == ''
and item.rc != 0
tags:
- wordpress-plugins-install-plugin
- wordpress-plugins-install-plugin-zip
- wordpress-plugins-install-plugin-zip-copy

- name: plugins | install | zip | install
command: >
wp-cli --allow-root --no-color --path='{{ item.item.0.path }}'
{{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ wordpress_data_path }}/plugins/{{ item.item.1.name }}.zip
with_items: "{{ _check_installation_plugins.results | default([]) }}"
when: >
item.item.1.name
and item.item.1.zip | default('') != ''
and item.item.1.url | default('') == ''
and item.rc != 0
tags:
- wordpress-plugins-install-plugin
- wordpress-plugins-install-plugin-zip
- wordpress-plugins-install-plugin-zip-install

- name: plugins | install | url
command: >
wp-cli --allow-root --no-color --path='{{ item.item.0.path }}'
{{ '--force' if item.item.1.force | default(false) else '' }} plugin install {{ item.item.1.url }}
with_items: "{{ _check_installation_plugins.results | default([]) }}"
when: >
item.item.1.name
and item.item.1.zip | default('') == ''
and item.item.1.url | default('') != ''
and item.rc != 0
tags:
- wordpress-plugins-install-plugin
- wordpress-plugins-install-plugin-url

- name: plugins | check install
command: >
Expand Down
15 changes: 3 additions & 12 deletions tasks/users.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# tasks file for wordpress, users
---
- name: users | create (data) directory
file:
path: "{{ wordpress_data_path }}"
state: directory
owner: root
group: root
mode: 0755
tags:
- wordpress-users-create-data-directory

- name: users | copy file
copy:
src: "{{ item.users.src }}"
dest: "{{ wordpress_data_path }}/{{ item.dbname }}.csv"
dest: "{{ wordpress_data_path }}/users/{{ item.dbname }}.csv"
owner: root
group: root
mode: 0644
Expand All @@ -27,7 +17,8 @@
command: >
wp-cli user import-csv
--allow-root --no-color --path='{{ item.item.path }}'
{{ wordpress_data_path }}/{{ item.item.dbname }}.csv {{ '--skip-update' if item.item.users.skip_update | default(true) else '' }}
{{ wordpress_data_path }}/users/{{ item.item.dbname }}.csv
{{ '--skip-update' if item.item.users.skip_update | default(true) else '' }}
--send-email
register: _check_installation_users
changed_when: "'Success' in _check_installation_users.stdout"
Expand Down
9 changes: 7 additions & 2 deletions tests/vagrant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ user = root
password = vagrant
EOF

# No PHP 5 support in 16.04
if $(lsb_release -r | grep -q '16.04'); then
# No .my.cnf needed for Debian 9 (MariaDB)
if $(lsb_release -c | grep -qE '(stretch)'); then
rm ~/.my.cnf;
fi

# No PHP 5 support in Ubuntu 16.04 and Debian 9
if $(lsb_release -c | grep -qE '(xenial|stretch)'); then
PHP_VERSION='7.0';
else
PHP_VERSION='5';
Expand Down
6 changes: 6 additions & 0 deletions tests/vagrant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
- name: contact-form-7
activate: false
- name: simple-fields
- name: advanced-custom-fields-pro
zip: ../../../files/wordpress/plugins/advanced-custom-fields-pro.zip
- name: gravityforms
zip: ../../../files/wordpress/plugins/gravityforms.zip
- name: wp-envato-market
url: https://github.com/envato/wp-envato-market/archive/master.zip
users: {}
options:
- command: add
Expand Down

0 comments on commit 27d03cf

Please sign in to comment.