Skip to content

Commit

Permalink
Run wp commands as user if specified
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
bviktor committed Nov 24, 2024
1 parent 32795b3 commit 83793d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

## Synopsys

This role lets you perform various tasks on your WordPress instances.
This role lets you perform various tasks on your WordPress instances. Currently the only supported task is update.

## Parameters

| Name | Required | Example | Description |
|---|---|---|---|
| `path` | no | `/var/www/html/wordpress` | Path to your WordPress instance. Only optional if `dry_run` is `true`. |
| `user` | no | `nginx` | User to perform the action as. Defaults to `root`. |
| `dry_run` | no | `true` | If `true`, only the required tools are installed, but the upgrade itself is not performed. Defaults to `false`. |

## Examples
Expand All @@ -18,6 +19,7 @@ This role lets you perform various tasks on your WordPress instances.
name: noobient.wordpress
vars:
path: '/var/www/html/wordpress'
user: nginx
dry_run: false
```
Expand Down
10 changes: 10 additions & 0 deletions tasks/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,38 @@
- name: "Update WordPress plugins in {{ path }}"
command:
cmd: "wp --allow-root --path={{ path }} --no-color plugin update --all"
become: true
become_user: "{{ eff_user }}"
changed_when: (wp_up_plugin_str not in wp_plugin_upd.stdout)
register: wp_plugin_upd

- name: "Update WordPress themes in {{ path }}"
command:
cmd: "wp --allow-root --path={{ path }} --no-color theme update --all"
become: true
become_user: "{{ eff_user }}"
changed_when: (wp_up_theme_str not in wp_theme_upd.stdout)
register: wp_theme_upd

- name: "Check for WordPress updates in {{ path }}"
command:
cmd: "wp --allow-root --path={{ path }} --no-color core check-update"
become: true
become_user: "{{ eff_user }}"
changed_when: false
register: wp_upd_chk

- name: "Update WordPress in {{ path }}" # noqa no-changed-when
command:
cmd: "wp --allow-root --path={{ path }} --no-color core update"
become: true
become_user: "{{ eff_user }}"
when: (wp_up_core_str not in wp_upd_chk.stdout)

- name: "Update WordPress database in {{ path }}"
command:
cmd: "wp --allow-root --path={{ path }} --no-color core update-db"
become: true
become_user: "{{ eff_user }}"
changed_when: (wp_up_db_str not in wp_db_upd.stdout)
register: wp_db_upd
6 changes: 6 additions & 0 deletions tests/install.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---
- name: Update APT cache
apt:
update_cache: true
register: noobient_apt_cache_updated
when: ansible_os_family == 'Debian' and noobient_apt_cache_updated is not defined

- name: Install WordPress dependencies
package:
name: "{{ packages }}"
Expand Down
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ wp_up_plugin_str: 'Success: Plugin already updated.'
wp_up_theme_str: 'Success: Theme already updated.'

eff_dry_run: "{{ dry_run | default(false) | bool }}"
eff_user: "{% if user is defined and user | length %}{{ user }}{% else %}root{% endif %}"

0 comments on commit 83793d4

Please sign in to comment.