DEBOPS.WPCLI(5)

NAME
debops.wpcli - Install WP-CLI framework using Ansible

SYNOPSIS

debops service/wpcli [--limit group,host,...] [--diff] [--check] [--tags tag1,tag2,...] [--skip-tags tag1,tag2,...] [<ansible-playbook options>] ...

DESCRIPTION

WP-CLI <https://wp-cli.org/> framework is a PHP script which can be used to manage WordPress <https://wordpress.org/> installations via the Linux shell. It provides a command line interface to WP Admin dashboard, provides an interface for cron task execution for a given WordPress website, create backups, and lots of other things.

The debops.wpcli Ansible role can be used to install WP-CLI on a host managed by DebOps, which in turn enables management of per-user WordPress websites. The role is designed with shared hosting environment in mind; users need to utilize other DebOps/Ansible roles to manage the webserver, database engine, PHP environment and UNIX accounts, etc.

GETTING STARTED

  Default host customization

The role provides the run-wp-cron Bash script which can be used to execute the WP Cron tasks via the command line or cron service.

A special daily cron job is enabled by default; it looks for the wp-config.php files in the /home and /srv directories and changes their permissions to 0600 if they are world-readable. This is done because WordPress installer creates these files with 0666 permissions, which is a security risk in shared hosting environments.

  Example inventory

To install the WP-CLI framework on a host, the host needs to be added to the [debops_service_wpcli] Ansible inventory group. This will also install the PHP environment required to use the script.

[debops_service_wpcli]
hostname

  Example playbook

If you are using this role without DebOps, here's an example Ansible playbook that uses the debops.wpcli role:

---
- name: Install WP-CLI framework
  collections: [ 'debops.debops', 'debops.roles01',
                 'debops.roles02', 'debops.roles03' ]
  hosts: [ 'debops_service_wpcli' ]
  become: True
  environment: '{{ inventory__environment | d({})
                   | combine(inventory__group_environment | d({}))
                   | combine(inventory__host_environment  | d({})) }}'
  pre_tasks:
    - name: Apply keyring configuration for php environment
      import_role:
        name: 'keyring'
      vars:
        keyring__dependent_apt_keys:
          - '{{ php__keyring__dependent_apt_keys }}'
        keyring__dependent_gpg_keys:
          - '{{ wpcli__keyring__dependent_gpg_keys }}'
      tags: [ 'role::keyring', 'skip::keyring', 'role::php', 'role::wpcli' ]
    - name: Prepare php environment
      import_role:
        name: 'php'
        tasks_from: 'main_env'
      tags: [ 'role::php', 'role::php:env', 'role::logrotate' ]
  roles:
    - role: apt_preferences
      tags: [ 'role::apt_preferences', 'skip::apt_preferences' ]
      apt_preferences__dependent_list:
        - '{{ php__apt_preferences__dependent_list }}'
    - role: cron
      tags: [ 'role::cron', 'skip::cron' ]
    - role: logrotate
      tags: [ 'role::logrotate', 'skip::logrotate' ]
      logrotate__dependent_config:
        - '{{ php__logrotate__dependent_config }}'
    - role: php
      tags: [ 'role::php', 'skip::php' ]
      php__dependent_packages:
        - '{{ wpcli__php__dependent_packages }}'
    - role: wpcli
      tags: [ 'role::wpcli', 'skip::wpcli' ]

  Ansible tags

You can use Ansible --tags or --skip-tags parameters to limit what tasks are performed during Ansible run. This can be used after a host was first configured to speed up playbook execution, when you are sure that most of the configuration is already in the desired state.

Available role tags:

role::wpcli
    Main role tag, should be used in the playbook to execute all of the role tasks as well as role dependencies.

AUTHOR
Maciej Delmanowski

COPYRIGHT
2014-2022, Maciej Delmanowski, Nick Janetakis, Robin Schneider and others