Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active July 28, 2016 17:38
Show Gist options
  • Save renoirb/1b42edac44c723185c9d to your computer and use it in GitHub Desktop.
Save renoirb/1b42edac44c723185c9d to your computer and use it in GitHub Desktop.
Use Salt to install WordPress plugins using either git or zip file
# /srv/salt/wordpress/plugin_macro.sls
{#
# ref:
# - https://gist.github.com/renoirb/1b42edac44c723185c9d
# - https://gist.github.com/renoirb/af8f738f2fd16ca1eb27
# - http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html#jinja-macros
# - http://www.pluginmirror.com/plugins
#}
{% macro wordpress_plugin(name, versionIdentifier, handler, wpDocroot, gitRepo=None) -%}
Install WordPress {{ name }} plugin using {{ handler }}:
{%- if handler == 'zip' %}
cmd.run:
- name: echo https://downloads.wordpress.org/plugin/{{ name ~ '.' ~ versionIdentifier }}.zip | xargs wget -qO- -O {{ wpDocroot }}/wp-content/plugins/{{ name }}.zip; unzip {{ wpDocroot }}/wp-content/plugins/{{ name }}.zip -d {{ wpDocroot }}/wp-content/plugins
- unless: test -d {{ wpDocroot }}/wp-content/plugins/{{ name }}
pkg.installed:
- name: unzip
{% endif -%}
{%- if handler == 'git' %}
git.latest:
- name: {{ gitRepo|default('https://github.com/wp-plugins/' ~ name) }}
- rev: {{ versionIdentifier }}
- target: {{ wpDocroot }}/wp-content/plugins/{{ name }}
- unless: test -d {{ wpDocroot }}/wp-content/plugins/{{ name }}
- submodules: True
pkg.installed:
- name: git
{% endif -%}
{%- endmacro %}
# /srv/salt/foo/init.sls
# Where we use the WordPress macro
{%- from "wordpress/plugin_macro.sls" import wordpress_plugin -%}
{% for n,v,m,g in [('nginx-helper', '1.8.4', 'zip', None),
('wp-api','1.2.1', 'git', 'https://github.com/WP-API/WP-API'),
('xili-language','2.16.1', 'zip', None)] %}
{{ wordpress_plugin(n,v,m,vhostDocroot,g) }}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment