1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Cleaner Dependencies e.g. for Sugarizer, Moodle, Node-Red, PBX, Elgg

This commit is contained in:
root 2020-02-04 15:03:59 -05:00
parent 106558aca9
commit 027832889b
88 changed files with 1212 additions and 909 deletions

View file

@ -0,0 +1,12 @@
- name: Enable http://box/moodle via Apache
command: a2ensite 022-moodle.conf
when: moodle_enabled | bool
- name: Disable http://box/moodle via Apache
command: a2dissite 022-moodle.conf
when: not moodle_enabled
- name: (Re)Start '{{ apache_service }}' systemd service
systemd:
name: "{{ apache_service }}" # apache2 or httpd, as set in /opt/iiab/iiab/vars/<OS>.yml
state: restarted

View file

@ -1,67 +0,0 @@
- name: Enable 'postgresql-iiab' systemd service, if moodle_enabled
systemd:
name: postgresql-iiab
state: started
enabled: yes
when: moodle_enabled
# if the only service using the backend db disable if not running
- name: Disable 'postgresql-iiab' systemd service, if not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)
systemd:
name: postgresql-iiab
state: stopped
enabled: no
when: not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)
# Apache
- name: Enable http://box/moodle via Apache
command: a2ensite 022-moodle.conf
when: apache_install and moodle_enabled
- name: Disable http://box/moodle via Apache
command: a2dissite 022-moodle.conf
when: apache_install and not moodle_enabled
- name: Restart '{{ apache_service }}' systemd service
systemd:
name: "{{ apache_service }}" # apache2 or httpd, as set in /opt/iiab/iiab/vars/<OS>.yml
state: restarted
when: apache_enabled | bool
# NGINX
- name: Enable http://box/moodle via NGINX, by installing {{ nginx_conf_dir }}/moodle-nginx.conf from template
template:
src: moodle-nginx.conf.j2
dest: "{{ nginx_conf_dir }}/moodle-nginx.conf"
when: nginx_install and moodle_enabled
- name: Disable http://box/moodle via NGINX, by removing {{ nginx_conf_dir }}/moodle-nginx.conf
file:
path: "{{ nginx_conf_dir }}/moodle-nginx.conf"
state: absent
when: nginx_install and not moodle_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted
when: nginx_enabled | bool
- name: Add 'moodle' variable values to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}"
section: moodle
option: "{{ item.option }}"
value: "{{ item.value | string }}"
with_items:
- option: name
value: Moodle
- option: description
value: '"Access the Moodle learning management system."'
- option: "moodle_base"
value: "{{ moodle_base }}"
- option: moodle_enabled
value: "{{ moodle_enabled }}"

View file

@ -1,19 +1,13 @@
- debug:
var: postgresql_install
- debug:
var: postgresql_enabled
- debug:
var: postgresql_installed
- name: "Set 'postgresql_install: True' and 'postgresql_enabled: True'"
set_fact:
postgresql_install: True
postgresql_enabled: True
- name: POSTGRESQL - run the 'postgresql' role
- name: POSTGRESQL - run 'postgresql' role (attempt to install & enable PostgreSQL)
include_role:
name: postgresql
- name: "Install packages: python-psycopg2, php-pgsql (OS's other than debuntu)"
package:
name:
@ -35,22 +29,22 @@
state: present
when: is_debuntu | bool
- name: "Install package: php{{ php_version }}-zip (ubuntu or debian-9+)"
- name: "Install package: php{{ php_version }}-zip (Ubuntu or Debian 9+)"
package:
name: "php{{ php_version }}-zip"
when: is_ubuntu or (is_debian and not is_debian_8)
- name: "Install package: php-pclzip (debian-8)"
package:
name: php-pclzip
when: is_debian_8 | bool
# - name: "Install package: php-pclzip (debian-8)"
# package:
# name: php-pclzip
# when: is_debian_8 | bool
- name: Determine if Moodle is already downloaded
- name: Does {{ moodle_base }}/config-dist.php exist? (indicating Moodle is/was installed)
stat:
path: "{{ moodle_base }}/config-dist.php"
register: moodle
- name: Download the latest Moodle repo
- name: Clone (i.e. use git to download) {{ moodle_repo_url }} to {{ moodle_base }}
git:
repo: "{{ moodle_repo_url }}"
dest: "{{ moodle_base }}"
@ -63,32 +57,32 @@
- name: Create dir {{ moodle_base }} owned by {{ apache_user }} (for config file?)
file:
state: directory
path: "{{ moodle_base }}"
owner: "{{ apache_user }}"
recurse: yes
state: directory
- name: Create dir {{ content_base }}/dbdata/moodle owned by {{ apache_user }}
file:
state: directory
path: "{{ content_base }}/dbdata/moodle"
owner: "{{ apache_user }}"
# mode: '0755'
state: directory
- name: Create dir {{ moodle_data }} owned by {{ apache_user }}:{{ apache_user }} with write permission 0770 # /library/moodle
- name: Create dir {{ moodle_data }} ({{ apache_user }}:{{ apache_user }}, '0770') # /library/moodle
file:
state: directory
path: "{{ moodle_data }}"
owner: "{{ apache_user }}"
group: "{{ apache_user }}"
mode: '0770'
state: directory
- name: Remove Apache's stock moodle.conf
- name: Remove stock /etc/{{ apache_conf_dir }}/moodle.conf
file:
path: "/etc/{{ apache_conf_dir }}/moodle.conf"
state: absent
- name: Install Apache's 022-moodle.conf from template, if moodle_enabled
- name: Install /etc/{{ apache_conf_dir }}/022-moodle.conf from template
template:
src: 022-moodle.j2
dest: "/etc/{{ apache_conf_dir }}/022-moodle.conf"
@ -96,10 +90,10 @@
# group: root
# mode: '0644'
- name: Restart postgresql-iiab
service:
- name: Start 'postgresql-iiab' systemd service, to configure Moodle's DB
systemd:
name: postgresql-iiab
state: restarted
state: started
- name: Create PostgreSQL db user Admin/changeme
postgresql_user:
@ -121,21 +115,21 @@
become: yes
become_user: postgres
- name: Install {{ moodle_base }}/moodle_installer from template
- name: Install {{ moodle_base }}/moodle_installer from template ('0755')
template:
src: moodle_installer
dest: "{{ moodle_base }}"
mode: '0755'
- name: Enable & Restart postgresql-iiab
service:
- name: (Re)Start 'postgresql-iiab' systemd service
systemd:
name: postgresql-iiab
state: restarted
enabled: yes
when: moodle_enabled | bool
#enabled: yes
#when: moodle_enabled | bool
- name: Restart Apache systemd service ({{ apache_service }})
service:
- name: (Re)Start '{{ apache_service }}' systemd service
systemd:
name: "{{ apache_service }}"
state: restarted
@ -148,10 +142,10 @@
shell: "{{ moodle_base }}/moodle_installer"
when: config.stat.exists is defined and not config.stat.exists
- name: Give read permission 0644 to {{ moodle_base }}/config.php # /opt/iiab/moodle/config.php
- name: Make {{ moodle_base }}/config.php readable, with permission '0644'
#command: chown -R {{ apache_user }} {{ moodle_base }}
file:
path: "{{ moodle_base }}/config.php"
path: "{{ moodle_base }}/config.php" # /opt/iiab/moodle
mode: '0644'
@ -163,6 +157,6 @@
- name: "Add 'moodle_installed: True' to {{ iiab_state_file }}"
lineinfile:
dest: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp: '^moodle_installed'
line: 'moodle_installed: True'

View file

@ -1,7 +1,82 @@
- name: "Install Moodle"
include_tasks: install.yml
when: moodle_install and not moodle_installed is defined
# "How do i fail a task in Ansible if the variable contains a boolean value?
# I want to perform input validation for Ansible playbooks"
# https://stackoverflow.com/questions/46664127/how-do-i-fail-a-task-in-ansible-if-the-variable-contains-a-boolean-value-i-want/46667499#46667499
- name: Enable Moodle
include_tasks: enable.yml
when: moodle_install or moodle_installed is defined
# We assume 0-init/tasks/validate_vars.yml has DEFINITELY been run, so no need
# to re-check whether vars are defined here. As Ansible vars cannot be unset:
# https://serverfault.com/questions/856729/how-to-destroy-delete-unset-a-variable-value-in-ansible
- name: Assert that "moodle_install is sameas true" (boolean not string etc)
assert:
that: moodle_install is sameas true
fail_msg: "PLEASE SET 'moodle_install: True' e.g. IN: /etc/iiab/local_vars.yml"
quiet: yes
- name: Assert that "moodle_enabled | type_debug == 'bool'" (boolean not string etc)
assert:
that: moodle_enabled | type_debug == 'bool'
fail_msg: "PLEASE GIVE VARIABLE 'moodle_enabled' A PROPER (UNQUOTED) ANSIBLE BOOLEAN VALUE e.g. IN: /etc/iiab/local_vars.yml"
quiet: yes
- name: Install Moodle if 'moodle_installed' not defined, e.g. in {{ iiab_state_file }} # /etc/iiab/iiab_state.yml
include_tasks: install.yml
when: moodle_installed is undefined
# - name: Enable 'postgresql-iiab' systemd service, if moodle_enabled
# systemd:
# name: postgresql-iiab
# deamon_reload: yes
# state: started
# enabled: yes
# when: moodle_enabled | bool
#
# # if the only service using the backend db disable if not running
# - name: Disable 'postgresql-iiab' systemd service, if 'not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)'
# systemd:
# name: postgresql-iiab
# state: stopped
# enabled: no
# when: not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)
- name: "Set 'postgresql_enabled: True'" if moodle_enabled
set_fact:
postgresql_enabled: True
when: moodle_enabled | bool
- name: "Set 'postgresql_enabled: False'" if 'not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)'
set_fact:
postgresql_enabled: False
when: not moodle_enabled and not (pathagar_enabled is defined and pathagar_enabled)
- name: POSTGRESQL - run 'postgresql' role (Enable&Start or Disable&Stop PostgreSQL)
include_role:
name: postgresql
#- name: Enable/Disable/Restart Apache if primary
- name: SHIM FOR NOW SO ALWAYS DO THE...Enable/Disable/Restart Apache
include_tasks: apache.yml
#when: not nginx_enabled
- name: Enable/Disable/Restart NGINX if primary
include_tasks: nginx.yml
when: nginx_enabled | bool
- name: Add 'moodle' variable values to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: moodle
option: "{{ item.option }}"
value: "{{ item.value | string }}"
with_items:
- option: name
value: Moodle
- option: description
value: '"Access the Moodle learning management system."'
- option: "moodle_base"
value: "{{ moodle_base }}"
- option: moodle_enabled
value: "{{ moodle_enabled }}"

View file

@ -0,0 +1,16 @@
- name: Enable http://box/moodle via NGINX, by installing {{ nginx_conf_dir }}/moodle-nginx.conf from template
template:
src: moodle-nginx.conf.j2
dest: "{{ nginx_conf_dir }}/moodle-nginx.conf" # /etc/nginx/conf.d
when: moodle_enabled | bool
- name: Disable http://box/moodle via NGINX, by removing {{ nginx_conf_dir }}/moodle-nginx.conf
file:
path: "{{ nginx_conf_dir }}/moodle-nginx.conf" # /etc/nginx/conf.d
state: absent
when: not moodle_enabled
- name: Restart 'nginx' systemd service
systemd:
name: nginx
state: restarted