From 2a16a82fd0fbecfadb8d9426cf0e9563fbc64043 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 9 Feb 2017 16:34:42 +0100 Subject: [PATCH] library/roles/smartgears/dataminer_app/tasks/install-gcube-key.yml: Remove the old keys when switching environment. library/roles/smartgears/smartgears/templates/get-scopes.j2: Fix the creation of the container.xml file. Updates were failing because the file was not writeable. --- .../dataminer_app/tasks/install-gcube-key.yml | 78 +++++++++++++------ .../smartgears/tasks/install-gcube-keys.yml | 6 +- smartgears/smartgears/templates/get-scopes.j2 | 9 ++- 3 files changed, 64 insertions(+), 29 deletions(-) diff --git a/smartgears/dataminer_app/tasks/install-gcube-key.yml b/smartgears/dataminer_app/tasks/install-gcube-key.yml index 83bad0f3..d55e5298 100644 --- a/smartgears/dataminer_app/tasks/install-gcube-key.yml +++ b/smartgears/dataminer_app/tasks/install-gcube-key.yml @@ -1,29 +1,57 @@ --- -- name: Install the production gcube keys - get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING owner={{ smartgears_user }} group={{ smartgears_user }} mode=0400 - with_items: - - '{{ gcube_prod_key_1 }}' - - '{{ gcube_prod_key_2 }}' - - '{{ gcube_prod_key_3 }}' - - '{{ gcube_prod_key_4 }}' - notify: Restart smartgears - when: install_gcube_prod_key - tags: [ 'dataminer', 'gcube_key', 'wps' ] +- block: + - name: Install the production gcube keys + get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600 + with_items: + - '{{ gcube_prod_key_1 }}' + - '{{ gcube_prod_key_2 }}' + - '{{ gcube_prod_key_3 }}' + - '{{ gcube_prod_key_4 }}' + notify: Restart smartgears + when: install_gcube_prod_key -- name: Install the devel gcube keys - get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING owner={{ smartgears_user }} group={{ smartgears_user }} mode=0400 - with_items: - - '{{ gcube_dev_key_1 }}' - - '{{ gcube_dev_key_2 }}' - - '{{ gcube_dev_key_3 }}' - notify: Restart smartgears - when: install_gcube_dev_key - tags: [ 'dataminer', 'gcube_key', 'wps' ] + - name: Remove the production gcube keys + file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSIN/{{ item.name }} state=absent + with_items: + - '{{ gcube_prod_key_1 }}' + - '{{ gcube_prod_key_2 }}' + - '{{ gcube_prod_key_3 }}' + - '{{ gcube_prod_key_4 }}' + notify: Restart smartgears + when: not install_gcube_prod_key -- name: Install the preprod gcube keys - get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING owner={{ smartgears_user }} group={{ smartgears_user }} mode=0400 - with_items: - - '{{ gcube_pre_key_1 }}' - notify: Restart smartgears - when: install_gcube_preprod_key + - name: Install the devel gcube keys + get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600 + with_items: + - '{{ gcube_dev_key_1 }}' + - '{{ gcube_dev_key_2 }}' + - '{{ gcube_dev_key_3 }}' + notify: Restart smartgears + when: install_gcube_dev_key + + - name: Remove the devel gcube keys + file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} state=absent + with_items: + - '{{ gcube_dev_key_1 }}' + - '{{ gcube_dev_key_2 }}' + - '{{ gcube_dev_key_3 }}' + notify: Restart smartgears + when: not install_gcube_dev_key + + - name: Install the preprod gcube keys + get_url: url={{ item.url }} dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600 + with_items: + - '{{ gcube_pre_key_1 }}' + notify: Restart smartgears + when: install_gcube_preprod_key + + - name: Remove the preprod gcube keys + file: dest={{ smartgears_instance_path }}/webapps/{{ dataminer_52north_webapp_name }}/ecocfg/PARALLEL_PROCESSING/{{ item.name }} state=absent + with_items: + - '{{ gcube_pre_key_1 }}' + notify: Restart smartgears + when: not install_gcube_preprod_key + + become: True + become_user: '{{ smartgears_user }}' tags: [ 'dataminer', 'gcube_key', 'wps' ] diff --git a/smartgears/smartgears/tasks/install-gcube-keys.yml b/smartgears/smartgears/tasks/install-gcube-keys.yml index 56d42404..9c45615b 100644 --- a/smartgears/smartgears/tasks/install-gcube-keys.yml +++ b/smartgears/smartgears/tasks/install-gcube-keys.yml @@ -1,7 +1,7 @@ --- - block: - name: Install the production gcube keys - get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ d4science_user }} mode=0400 + get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ d4science_user }} mode=0600 with_items: - '{{ gcube_prod_key_1 }}' - '{{ gcube_prod_key_2 }}' @@ -21,7 +21,7 @@ when: not install_gcube_prod_key - name: Install the devel gcube keys - get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ d4science_user }} mode=0400 + get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ d4science_user }} mode=0600 with_items: - '{{ gcube_dev_key_1 }}' - '{{ gcube_dev_key_2 }}' @@ -39,7 +39,7 @@ when: not install_gcube_dev_key - name: Install the preprod gcube keys - get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0400 + get_url: url={{ item.url }} dest=/{{ gcube_tomcat_lib_dir }}/{{ item.name }} owner={{ smartgears_user }} group={{ smartgears_user }} mode=0600 with_items: - '{{ gcube_pre_key_1 }}' notify: Restart smartgears diff --git a/smartgears/smartgears/templates/get-scopes.j2 b/smartgears/smartgears/templates/get-scopes.j2 index c72de226..5f835fbf 100644 --- a/smartgears/smartgears/templates/get-scopes.j2 +++ b/smartgears/smartgears/templates/get-scopes.j2 @@ -59,7 +59,14 @@ else fi # Now that we have the tokens, we can assemble the container.xml file -cat $CONTAINER_XML_HEAD $SCOPES_FILE $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE +chmod 640 $CONTAINER_XML_FILE +CREATE_CONTAINER_XML_RES=0 +CREATE_CONTAINER_XML=$( cat $CONTAINER_XML_HEAD $SCOPES_FILE $CONTAINER_XML_TAIL > $CONTAINER_XML_FILE ) +CREATE_CONTAINER_XML_RES=$? +if [ $CREATE_CONTAINER_XML_RES -ne 0 ] ; then + logger "$LOG_PREFIX $CONTAINER_XML_FILE cannot be updated. Error is $CREATE_CONTAINER_XML" + exit $CREATE_CONTAINER_XML_RES +fi chmod 440 $CONTAINER_XML_FILE logger "$LOG_PREFIX $CONTAINER_XML_FILE updated"