Skip to content

Commit

Permalink
Moodle support
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
bviktor committed Nov 28, 2024
1 parent 28f014c commit 64375f5
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 40 deletions.
9 changes: 5 additions & 4 deletions tasks/main2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
- include_tasks: apt_cache.yml
when: ansible_os_family == 'Debian' and noobient_apt_cache_updated is not defined

- include_tasks: wordpress.yml
when: (noobient_nginx_wp_installed is not defined) and (mode == 'wordpress')

# Gotta have this before WP for PHP version
- include_tasks: php.yml
when: (noobient_nginx_php_installed is not defined) and (mode == 'php' or mode == 'wordpress')
when: (noobient_nginx_php_installed is not defined) and (mode == 'php' or mode == 'wordpress' or mode == 'moodle')

- include_tasks: php_apps.yml
when: (noobient_nginx_phpapps_installed is not defined) and (mode == 'wordpress' or mode == 'moodle')

- include_tasks: nginx.yml
when: noobient_nginx_installed is not defined
Expand Down
9 changes: 8 additions & 1 deletion tasks/php.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
- name: Install PHP
- name: "Enable PHP {{ noobient_nginx_moodle_php_ver }} stream"
command:
cmd: "dnf -y module switch-to php:{{ noobient_nginx_moodle_php_ver }}"
register: noobient_nginx_php_switchto
changed_when: ('Nothing to do' not in noobient_nginx_php_switchto.stdout)
when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora' and mode == 'moodle'

- name: Install PHP-FPM
package:
name: php-fpm
state: latest
Expand Down
91 changes: 91 additions & 0 deletions tasks/php_apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
- name: Enable EPEL repo
package:
name: epel-release
state: latest
when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora' and mode == 'moodle'

- name: Install packages common for WordPress / Moodle
package:
name: "{{ packages }}"
state: latest
vars:
packages:
- php-pdo
- php-gd
- php-opcache
- php-mbstring
- php-xml
- "php{% if ansible_os_family == 'Debian' %}{{ noobient_nginx_php_ver }}{% endif %}-intl"
- "php{% if ansible_os_family == 'RedHat' %}-pecl{% else %}{{ noobient_nginx_php_ver }}{% endif %}-zip"
register: noobient_nginx_phpapps_installed

- name: Install packages for WordPress
package:
name: "{{ packages }}"
state: latest
vars:
packages:
- php-mysqlnd
- php-json
register: noobient_nginx_wp_installed
when: mode == 'wordpress' and noobient_nginx_wp_installed is not defined

- name: Install packages for Moodle
package:
name: "{{ packages }}"
state: latest
vars:
packages:
- php-devel
- libsodium
- libsodium-devel
- php-pgsql
- php-soap
- php-pear
register: noobient_nginx_moodle_installed
when: mode == 'moodle' and noobient_nginx_moodle_installed is not defined

- name: Install libsodium
command:
cmd: pecl install --nodeps libsodium
register: noobient_nginx_sodium_install
changed_when: noobient_nginx_sodium_installed_str not in noobient_nginx_sodium_install.stdout
failed_when: noobient_nginx_sodium_install.rc != 0 and noobient_nginx_sodium_install.rc != 1
when: mode == 'moodle' and noobient_nginx_sodium_install is not defined

# Not available on EL8
- name: Install ImageMagick PHP extension
package:
name: "php{% if ansible_os_family == 'RedHat' %}-pecl{% else %}{{ noobient_nginx_php_ver }}{% endif %}-imagick"
state: latest
when: not (ansible_distribution_major_version == '8' and ansible_os_family == 'RedHat')

- name: Set PHP options for Moodle
ini_file:
path: "{{ noobient_nginx_php_ini }}"
section: PHP
option: "{{ noobient_nginx_php_moodle_opt.option }}"
value: "{{ noobient_nginx_php_moodle_opt.value }}"
mode: '0644'
backup: true
loop:
- { option: 'max_input_vars', value: '5000' }
loop_control:
loop_var: noobient_nginx_php_moodle_opt
notify: Reload PHP
when: mode == 'moodle'

- name: Enable libsodium PHP module
ini_file:
path: /etc/php.d/99-libsodium.ini
create: true
section: ''
option: extension
value: sodium.so
no_extra_spaces: true
owner: root
group: root
mode: '0644'
notify: Reload PHP
when: mode == 'moodle'
24 changes: 0 additions & 24 deletions tasks/wordpress.yml

This file was deleted.

2 changes: 1 addition & 1 deletion templates/host.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ server
server_name {{ domain }}{% if eff_www_mode == 'serve' %} www.{{ domain }}{% endif %};
root {{ eff_path }};

{% if mode == 'php' or mode == 'wordpress' %}
{% if mode == 'php' or mode == 'wordpress' or mode == 'moodle' %}
include php.conf;

{% elif mode == 'proxy' %}
Expand Down
8 changes: 8 additions & 0 deletions tests/batch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Test batch mode and idempotency at the same time
- include_role:
name: "{{ playbook_dir.split('/')[:-1] | last }}"
vars:
nginx_batch:
- { domain: foo3.com, mode: redirect, new_domain: bar.com, ssl_selfsigned: true }
- { domain: foo.com, mode: proxy, ssl_selfsigned: 'true', host_port: '7777', proxy_port: '8888' }
11 changes: 2 additions & 9 deletions tests/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
---
- hosts: 127.0.0.1
tasks:
- include_tasks: php.yml
- include_tasks: single.yml

# Test batch mode and idempotency at the same time
- include_role:
name: "{{ playbook_dir.split('/')[:-1] | last }}"
vars:
nginx_batch:
- { domain: foo3.com, mode: redirect, new_domain: bar.com, ssl_selfsigned: true }
- { domain: foo.com, mode: proxy, ssl_selfsigned: 'true', host_port: '7777', proxy_port: '8888' }
- include_tasks: php.yml
- include_tasks: batch.yml
3 changes: 2 additions & 1 deletion tests/single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
vars:
domain: foo1.com
ssl_selfsigned: true
mode: wordpress
host_port: 8443
mode: moodle

- include_role:
name: "{{ playbook_dir.split('/')[:-1] | last }}"
Expand Down
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ eff_new_domain: "{{ new_domain | default('') }}"

default_fpm_sock: /run/php-fpm/www.sock

noobient_nginx_moodle_php_ver: '8.2'
noobient_nginx_sodium_installed_str: 'pecl/libsodium is already installed and is the same as the released version'

# Check with:
# semanage port -l | grep '^http_port_t '
# semanage port -l | grep '^http_cache_port_t '
Expand Down

0 comments on commit 64375f5

Please sign in to comment.