Trying to install a plugin only for remote server

I wrote this script based on the wp core is-installed check. It should be simple and straightforward but it does not work, and I can’t figure out why. At first I believed the is-installed check just might not work with WP-CLI, but honestly I don’t even know enough to know where to start debugging this.

- name: Lcache Installed?
  become_user: "{{ web_user }}"
  command: wp plugin is-installed wp-lcache
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  register: lcache_installed
  changed_when: false
  failed_when: lcache_installed.stderr == ""

- block:
  - name: Run wp plugin install wp-lcache --activate
    become_user: "{{ web_user }}"
    command: wp plugin install wp-lcache --activate
    args:
      chdir: "{{ deploy_helper.new_release_path }}"

  - name: Run wp lcache enable
    become_user: "{{ web_user }}"
    command: wp lcache enable
    args:
      chdir: "{{ deploy_helper.new_release_path }}"

  when: lcache_installed | success

Why not use composer for managing the plugins?

You’re right I’m dumb. I forgot I can use composer and then just keep it active on remote install. Now the only thing left is that I need to run wp lcache enable if it’s activated.

You can add this wp cli command to the site specific deploy yml.

The plugins are activated when transferring the database + uploads/ to WordPress site (because it also contains the configuration for plugin status).
It is also possible to run wp plugin activate lcache before wp lcache enable, in the right hook after which the plugins were installed by composer.

I currently have it in the site specific build-after, but I’m thinking the plugin activation detection is not working correctly so these commands don’t run.

wp plugin activate <name> should be idempotent, when the plugin is already activated it will just skip.

1 Like