From a1c4a88fa8fff5d5887e648daf0be68e44cbf671 Mon Sep 17 00:00:00 2001 From: Louise Davies Date: Wed, 22 Feb 2023 12:53:41 +0000 Subject: [PATCH] Add ability to install ICAT DB triggers via a variable --- roles/icat_server/defaults/main.yml | 1 + roles/icat_server/tasks/main.yml | 4 ++ roles/icat_server/tasks/setup-db-triggers.yml | 40 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 roles/icat_server/tasks/setup-db-triggers.yml diff --git a/roles/icat_server/defaults/main.yml b/roles/icat_server/defaults/main.yml index 2fbdac7..d4bad35 100644 --- a/roles/icat_server/defaults/main.yml +++ b/roles/icat_server/defaults/main.yml @@ -6,3 +6,4 @@ icat_server_maxEntities: "10000" icat_server_authn_list: "{% if ansible_local.local.instantiations.authn_simple is defined and ansible_local.local.instantiations.authn_simple == 'true' %}simple {% endif %}{% if ansible_local.local.instantiations.authn_db is defined and ansible_local.local.instantiations.authn_db == 'true' %}db {% endif %}{% if ansible_local.local.instantiations.authn_anon is defined and ansible_local.local.instantiations.authn_anon == 'true' %}anon {% endif %}{% if ansible_local.local.instantiations.authn_ldap is defined and ansible_local.local.instantiations.authn_ldap == 'true' %}ldap {% endif %}{% if ansible_local.local.instantiations.authn_ip_clf is defined and ansible_local.local.instantiations.authn_ip_clf == 'true' %}ip_clf {% endif %}{% if ansible_local.local.instantiations.authn_uows_clf is defined and ansible_local.local.instantiations.authn_uows_clf == 'true' %}uows_clf {% endif %}" icat_server_authn_ldap_admin: "true" icat_server_lucene_populateBlockSize: "1000" +icat_server_install_db_triggers: true diff --git a/roles/icat_server/tasks/main.yml b/roles/icat_server/tasks/main.yml index ed07b67..6c78f2f 100644 --- a/roles/icat_server/tasks/main.yml +++ b/roles/icat_server/tasks/main.yml @@ -106,3 +106,7 @@ - name: "Setup icat_server if not setup" import_tasks: tasks/installation.yml when: (ansible_local is not defined) or (ansible_local.local is not defined) or (ansible_local.local.instantiations is not defined) or (ansible_local.local.instantiations.icat_server is not defined) or (ansible_local.local.instantiations.icat_server != 'true') + +- name: "Setup db triggers if enabled and not setup" + import_tasks: tasks/setup-db-triggers.yml + when: icat_server_install_db_triggers and ((ansible_local is not defined) or (ansible_local.local is not defined) or (ansible_local.local.instantiations is not defined) or (ansible_local.local.instantiations.icat_server_db_triggers is not defined) or (ansible_local.local.instantiations.icat_server_db_triggers != 'true')) diff --git a/roles/icat_server/tasks/setup-db-triggers.yml b/roles/icat_server/tasks/setup-db-triggers.yml new file mode 100644 index 0000000..e704852 --- /dev/null +++ b/roles/icat_server/tasks/setup-db-triggers.yml @@ -0,0 +1,40 @@ +--- +- name: "Import: Check payara is running" + import_tasks: "{{ role_path }}/../payara/tasks/status.yml" + +- name: "Stop payara if it is running" + shell: "/usr/local/bin/payara-init stop" + become: true + become_user: root + args: + chdir: /root + executable: /bin/bash + when: payaraStatus.rc == 0 + +- name: Attempt to install Maria DB triggers + block: + - name: "Install db triggers" + shell: "mysql --user={{ db_root_username }} --password={{ db_root_password }} --database={{ icat_database }} < /home/{{ payara_user }}/install/icat.server/create_triggers_mysql_5_0.sql" + become: true + become_user: root + args: + chdir: /root + executable: /bin/bash + - name: "Set fact on host to record that database triggers have been instantiated" + ini_file: + path: /etc/ansible/facts.d/local.fact + section: "instantiations" + option: "icat_server_db_triggers" + value: "true" + no_extra_spaces: true + create: false + when: ansible_local.local.instantiations.mariadb is defined and ansible_local.local.instantiations.mariadb == 'true' + always: + - name: "Start payara if it was running at the beginning of this script" + shell: "/usr/local/bin/payara-init start" + become: true + become_user: root + args: + chdir: /root + executable: /bin/bash + when: payaraStatus.rc == 0