diff --git a/README.md b/README.md index ef37f17..a0e6272 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/tasks/update.yml b/tasks/update.yml index 5f23553..03b073e 100644 --- a/tasks/update.yml +++ b/tasks/update.yml @@ -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 diff --git a/tests/install.yml b/tests/install.yml index 26a2f97..7c5fcbf 100644 --- a/tests/install.yml +++ b/tests/install.yml @@ -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 }}" diff --git a/vars/main.yml b/vars/main.yml index 4c8e4d3..a860ddd 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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 %}"