1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-13 03:32:12 +00:00
iiab/roles/wordpress/tasks/install.yml

178 lines
9.1 KiB
YAML
Raw Normal View History

2017-11-29 21:05:36 +00:00
# "Emergency" reinstalls (from /opt/iiab/downloads/wordpress.tar.gz
# to /library/wordpress) should also work offline...
2017-11-15 16:03:08 +00:00
#
2017-11-30 01:25:09 +00:00
# ONLINE OR OFFLINE, IF YOU NEED A CLEAN REINSTALL OF WORDPRESS DURING YOUR
2018-07-12 22:13:58 +00:00
# NEXT RUN OF "./runrole wordpress" OR "./iiab-install" PLEASE FIRST DO:
2017-11-29 21:05:36 +00:00
#
# - "mv /library/wordpress /library/wordpress.old"
# - back up WordPress's database then drop it
2017-11-15 16:03:08 +00:00
#
2018-09-22 15:03:44 +00:00
# REASON: "keep_newer: yes" below tries to preserve WordPress's self-upgrades
# and security enhancements using timestamps under /library/wordpress, as these
2018-09-22 15:03:44 +00:00
# can arise without warning when WordPress is online, since WordPress ~4.8
2017-11-15 16:03:08 +00:00
- name: "Set 'mysql_install: True' and 'mysql_enabled: True'"
set_fact:
mysql_install: True
mysql_enabled: True
- name: MYSQL - run 'mysql' role (attempt to install & enable MySQL / MariaDB)
include_role:
name: mysql
- name: FAIL (STOP THE INSTALL) IF 'mysql_installed is undefined'
fail:
msg: "WordPress install cannot proceed, as MySQL / MariaDB is not installed."
when: mysql_installed is undefined
- name: Record (initial) disk space used
shell: df -B1 --output=used / | tail -1
register: df1
- name: Provision MySQL DB
include_tasks: setup.yml
# 2021-06-29: PHP modules, covering "RECOMMENDED" and "OPTIONAL" sections here:
# https://make.wordpress.org/hosting/handbook/server-environment/
- name: Install libsodium23 + 8 PHP packages (run 'php -m' or 'php -i' to verify)
package:
name:
- libsodium23 # Likewise installed in nginx/tasks/install.yml via php{{ php_version }}-fpm AND httpd/tasks/install.yml via libapache2-mod-php{{ php_version }} AND moodle/tasks/install.yml -- it can ALSO be auto-installed by phpX.Y-cgi OR phpX.Y-cli as confirmed by 'apt rdepends libsodium23' -- VERIFY USING 'php -i | grep sodium' AND 'apt list "*sodium*"'
- php{{ php_version }}-bcmath # OPTIONAL: Likewise installed in nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
#- php{{ php_version }}-common # Auto-installed as an apt dependency. REGARDLESS: php{{ php_version }}-common superset php{{ php_version }}-cli is auto-installed by php{{ php_version }}-fpm in nginx/tasks/install.yml
- php{{ php_version }}-curl # Likewise installed in moodle/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
- php-imagick # BUT drags in Apache's libapache2-mod-phpX.Y etc, as confirmed by 'apt depends php-imagick' -- while php{{ php_version }}-imagick installs (despite not being shown within 'apt list "php*imagick"') it's no better -- and 'apt depends phpX.Y-imagick' mysteriously does NOT show its deps. Likewise installed in nextcloud/tasks/install.yml
- php{{ php_version }}-intl # OPTIONAL: Likewise installed in mediawiki/tasks/install.yml, moodle/tasks/install.yml, nextcloud/tasks/install.yml
#- php{{ php_version }}-json # See stanza just below
- php{{ php_version }}-mbstring # Likewise installed in mediawiki/tasks/install.yml, moodle/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
- php{{ php_version }}-mysql # Likewise installed in mysql/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
- php{{ php_version }}-xml # Likewise installed in mediawiki/tasks/install.yml, moodle/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml -- AND REGARDLESS dragged in later by Admin Console's use of php-pear for roles/cmdsrv/tasks/main.yml -- run 'php -m | grep -i xml' which in the end shows {libxml, SimpleXML, xml, xmlreader, xmlwriter}
- php{{ php_version }}-zip # Likewise installed in moodle/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
state: present
# For PHP >= 8.0: phpX.Y-json is baked into PHP itself.
# For PHP < 8.0: phpX.Y-json auto-installed by phpX.Y-fpm AND phpX.Y-cli in 3-base-server's nginx/tasks/install.yml, as confirmed by: apt rdepends phpX.Y-json
#
#- name: Install php{{ php_version }}-json if PHP < 8.0
# package:
# name: php{{ php_version }}-json
# state: present
# when: php_version is version('8.0', '<')
- name: "Run roles/www_options/tasks/php-settings.yml with 'nginx_high_php_limits: False' by default"
include_tasks: roles/www_options/tasks/php-settings.yml
when: php_settings_done is undefined
- name: Delete {{ downloads_dir }}/wordpress.tar.gz if it exists
file:
path: "{{ downloads_dir }}/wordpress.tar.gz"
state: absent
- name: Download {{ wordpress_download_base_url }}/{{ wordpress_src }} to {{ downloads_dir }}/wordpress.tar.gz
command: wget {{ wordpress_download_base_url }}/{{ wordpress_src }} -O {{ downloads_dir }}/wordpress.tar.gz
# 2022-05-04: Ansible approach below (get_url) fails with HTTP Error 429
# (Too Many Requests) b/c Ansible's User-Agent string? Affecting 1 user in
# England and another user in Scotland, but not affecting many other
# countries/ISP's apparently? WordPress must have recently changed their
# hosting arrangements for https://wordpress.org/latest.tar.gz
# get_url:
# url: "{{ wordpress_download_base_url }}/{{ wordpress_src }}"
# dest: "{{ downloads_dir }}"
# timeout: "{{ download_timeout }}"
# register: wp_download_output
2017-05-27 18:09:50 +00:00
# - name: Symlink {{ downloads_dir }}/wordpress.tar.gz -> {{ wp_download_output.dest }}
# file:
# src: "{{ wp_download_output.dest }}"
# path: "{{ downloads_dir }}/wordpress.tar.gz" # /opt/iiab/downloads
# state: link
# when: wp_download_output.dest is defined
2017-11-15 16:03:08 +00:00
- name: Does {{ downloads_dir }}/wordpress.tar.gz exist?
2017-11-15 16:03:08 +00:00
stat:
2020-01-12 00:48:50 +00:00
path: "{{ downloads_dir }}/wordpress.tar.gz" # /opt/iiab/downloads
register: wp_tar_gz
2017-11-15 16:03:08 +00:00
2020-01-12 00:48:50 +00:00
- name: FAIL (force Ansible to exit) IF {{ downloads_dir }}/wordpress.tar.gz doesn't exist
2017-11-15 16:03:08 +00:00
fail:
msg: "{{ downloads_dir }}/wordpress.tar.gz is REQUIRED in order to install WordPress."
when: not wp_tar_gz.stat.exists
2017-11-15 16:03:08 +00:00
2020-01-18 04:35:24 +00:00
- name: "Unpack {{ downloads_dir }}/wordpress.tar.gz to permanent location {{ wp_install_path }}/wordpress - owner: root, group: {{ apache_user }}, mode: '0664', keep_newer: yes"
2017-11-15 16:03:08 +00:00
unarchive:
2020-01-18 04:35:24 +00:00
src: "{{ downloads_dir }}/wordpress.tar.gz" # /opt/iiab/downloads
dest: "{{ wp_install_path }}" # /library
2020-01-18 03:21:40 +00:00
owner: root # 2020-01-17: confirmed that wordpress.tar.gz (otherwise) unpacks as nobody:nogroup, with all files as '0644', and all dirs as '0755'
2020-01-11 18:17:50 +00:00
group: "{{ apache_user }}" # DO WE REALLY STILL WANT THIS FOR NGINX?
2020-01-18 03:21:40 +00:00
mode: '0664' # PHP/Apache/NGINX apparently need g+rw (group write access, not just read) similar to '0775' for directory traversing below
2017-11-15 16:03:08 +00:00
keep_newer: yes
2017-05-27 18:09:50 +00:00
2020-01-18 03:21:40 +00:00
- name: Make {{ wp_abs_path }} directories 775 so PHP/Apache/NGINX can traverse and write (above files remain 664)
command: "/usr/bin/find {{ wp_abs_path }} -type d -exec chmod 775 {} +" # /library/wordpress
2017-05-27 18:09:50 +00:00
2020-01-18 03:21:40 +00:00
# 4 stanzas to install wp-keys.php.BAK, wp-keys.php & wp-config.php into /library/wordpress
- name: Install {{ wp_abs_path }}/wp-keys.php.BAK from template (if file does not already exist) in case download of 8 dynamically-generated salts/keys fails below
2017-12-08 05:49:24 +00:00
copy:
src: wp-keys.php.BAK
2020-01-18 03:21:40 +00:00
dest: "{{ wp_abs_path }}/wp-keys.php.BAK" # /library/wordpress
owner: root
2020-01-11 18:17:50 +00:00
group: "{{ apache_user }}" # DO WE REALLY STILL WANT THIS FOR NGINX?
mode: '0640'
2020-01-18 03:21:40 +00:00
force: no # Preserve site's unique keys, as might have been placed into .BAK during an earlier run, by the script below
2017-05-27 18:09:50 +00:00
2018-10-31 06:22:41 +00:00
- name: Install script /tmp/get-iiab-wp-salts from template
2017-12-08 05:49:24 +00:00
template:
src: get-iiab-wp-salts.j2
dest: /tmp/get-iiab-wp-salts
2020-01-18 03:21:40 +00:00
owner: root
group: root
2020-01-11 18:17:50 +00:00
mode: '0700'
2017-05-27 18:09:50 +00:00
2020-01-18 03:21:40 +00:00
- name: Run /tmp/get-iiab-wp-salts to download 8 random salts/keys, creating a new {{ wp_abs_path }}/wp-keys.php (or if nec, copy from known/prior {{ wp_abs_path }}/wp-keys.php.BAK) # /library/wordpress
command: /tmp/get-iiab-wp-salts
#when: internet_available # Better to run it every time, installing from wp-keys.php.BAK if download fails
2017-05-27 18:09:50 +00:00
2020-01-18 03:21:40 +00:00
# Don't Bother: /tmp file are deleted on reboot!
#- name: Remove script /tmp/get-iiab-wp-salts
# file:
# path: /tmp/get-iiab-wp-salts
# state: absent
2017-05-27 18:09:50 +00:00
2020-01-18 03:21:40 +00:00
- name: Install {{ wp_abs_path }}/wp-config.php # /library/wordpress
2017-12-08 05:49:24 +00:00
template:
src: wp-config.php.j2
dest: "{{ wp_abs_path }}/wp-config.php"
2020-01-18 03:21:40 +00:00
owner: root
2020-01-11 18:17:50 +00:00
group: "{{ apache_user }}" # DO WE REALLY STILL WANT THIS FOR NGINX?
mode: '0660' # Others strongly recommend '0600' (or do PHP/Apache/NGINX really need group read & write permissions?)
2017-05-27 18:09:50 +00:00
2020-01-30 09:00:00 +00:00
# RECORD WordPress AS INSTALLED
- name: Record (final) disk space used
shell: df -B1 --output=used / | tail -1
register: df2
- name: Add 'wordpress_disk_usage = {{ df2.stdout|int - df1.stdout|int }}' to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: wordpress
option: wordpress_disk_usage
value: "{{ df2.stdout|int - df1.stdout|int }}"
2020-01-30 09:00:00 +00:00
- name: "Set 'wordpress_installed: True'"
set_fact:
wordpress_installed: True
- name: "Add 'wordpress_installed: True' to {{ iiab_state_file }}"
2019-09-09 17:14:13 +00:00
lineinfile:
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
2019-09-09 17:14:13 +00:00
regexp: '^wordpress_installed'
2019-10-07 17:11:21 +00:00
line: 'wordpress_installed: True'