diff --git a/ckan/ckan/defaults/main.yml b/ckan/ckan/defaults/main.yml index e0bbb17..c6be1ab 100644 --- a/ckan/ckan/defaults/main.yml +++ b/ckan/ckan/defaults/main.yml @@ -16,9 +16,12 @@ ckan_libdir: /usr/lib/ckan ckan_virtenv: '{{ ckan_libdir }}/default' ckan_file_storage_dir: /var/lib/ckan/dev ckan_config_file: /etc/ckan/default/production.ini +ckan_webapp_port: 8080 ckan_solr_port: 8983 ckan_shell_user: ckan ckan_logdir: /var/log/ckan +ckan_db_name: ckan +ckan_db_user: ckan # The order is important ckan_geonetwork_harvester: False @@ -51,10 +54,6 @@ ckan_ldap_email: mail ckan_ldap_prevent_edits: True ckan_ldap_fallback: True -users_system_users: - - { login: '{{ ckan_shell_user }}', name: "CKAN user", home: '/usr/lib', createhome: 'no', ssh_key: '{{ francesco_mangiacrapa }}', shell: '/bin/bash', admin: False, log_as_root: True } - - # Needed to install some CKAN plugins additional_packages: - git diff --git a/smartgears/ckan_connector/defaults/main.yml b/smartgears/ckan_connector/defaults/main.yml new file mode 100644 index 0000000..730ee38 --- /dev/null +++ b/smartgears/ckan_connector/defaults/main.yml @@ -0,0 +1,8 @@ +--- +gcube_repository: 'gcube-snapshots' +ckan_connector_plugin_install: False +ckan_connector_ver: 1.0.0 +ckan_connector_name: 'ckan_connector-{{ ckan_connector_ver }}.war' +ckan_connector_url: 'http://maven.research-infrastructures.eu/nexus/content/repositories/{{ gcube_repository }}/org/gcube/data/access/{{ ckan_connector_ver}}/{{ ckan_connector_name }}' +ckan_connector_war_file: ckan-connector.war +ckan_connector_user: ckan_connector diff --git a/smartgears/ckan_connector/files/ckan-connector.war b/smartgears/ckan_connector/files/ckan-connector.war new file mode 100644 index 0000000..664464b Binary files /dev/null and b/smartgears/ckan_connector/files/ckan-connector.war differ diff --git a/smartgears/ckan_connector/tasks/main.yml b/smartgears/ckan_connector/tasks/main.yml new file mode 100644 index 0000000..c3a9564 --- /dev/null +++ b/smartgears/ckan_connector/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- block: + + - name: Get the CKAN connector war file + #get_url: url={{ ckan_connector_url }} dest={{ smartgears_instance_path }}/webapps/{{ ckan_connector_war_file }} + copy: src={{ ckan_connector_war_file }} dest={{ smartgears_instance_path }}/webapps/{{ ckan_connector_war_file }} + + - name: Unpack the CKAN connector war file + shell: mkdir {{ smartgears_instance_path }}/webapps/ckan-connector ; cd {{ smartgears_instance_path }}/webapps/ckan-connector ; jar xf {{ smartgears_instance_path }}/webapps/{{ ckan_connector_war_file }} + args: + creates: '{{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF/web.xml' + + - name: Install the CKAN connector web.xml template + template: src=ckan-web.xml.j2 dest={{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF/web.xml mode=0440 + + - name: Install the CKAN connector fixer script + become: False + template: src=ckan-connector-fixer.sh.j2 dest=/usr/local/bin/ckan-connector-fixer owner=root group=root mode=0550 + + - name: Fix the CKAN connector web.xml + become: False + shell: /usr/local/bin/ckan-connector-fixer + args: + creates: '{{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF/.web.xml.configured' + notify: Restart smartgears + + become: True + become_user: '{{ smartgears_user }}' + when: ckan_connector_plugin_install + tags: [ 'smartgears', 'ckan', 'ckan_connector', 'tomcat' ] diff --git a/smartgears/ckan_connector/templates/ckan-connector-fixer.sh.j2 b/smartgears/ckan_connector/templates/ckan-connector-fixer.sh.j2 new file mode 100644 index 0000000..7369d9f --- /dev/null +++ b/smartgears/ckan_connector/templates/ckan-connector-fixer.sh.j2 @@ -0,0 +1,56 @@ +#!/bin/bash + +CK_WEB_DIR={{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF +CK_WEB_XML=$CK_WEB_DIR/web.xml +CK_DB_NAME={{ ckan_db_name }} +CK_DB_USER={{ ckan_db_user }} +CK_DB_HOST={{ psql_db_host }} +CK_ADMIN={{ ckan_connector_user }} +CK_ADMIN_PWD={{ ckan_connector_user_pwd }} +CK_INI=/etc/ckan/default/production.ini +API_KEY= +CKAN_KEY= +SQL_FILE=$( mktemp /tmp/XXXXXX.sql ) + +{% raw %} + +# Set the CKAN python virtualenv +. /usr/lib/ckan/default/bin/activate +cd /usr/lib/ckan/default/src/ckan +# Create the admin user +paster sysadmin add $CK_ADMIN -c $CK_INI << EOF +y +$CK_ADMIN_PWD +$CK_ADMIN_PWD +EOF + +# Get the admin key +echo "update \"user\" set state = 'active' where name = '${CK_ADMIN}';" > $SQL_FILE +echo "select apikey from \"user\" where name = '${CK_ADMIN}' and state = 'active';" >> $SQL_FILE +API_KEY=$( psql -t -n -q -h $CK_DB_HOST -U $CK_DB_USER -w $CK_DB_NAME -f $SQL_FILE ) + +[ $? -ne 0 ] && exit 1 + +CKAN_KEY=$( grep ^beaker\.session\.secret $CK_INI | awk '{ print $3 }' ) + +[ $? -ne 0 ] && exit 1 + +# Use the admin key on the connector web.xml +[ ! -z $API_KEY ] && sed -i -e "s#@CKAN_API_KEY@#${API_KEY}#g" $CK_WEB_XML + +# Use the ckan key on the connector web.xml +[ ! -z $CKAN_KEY ] && sed -i -e "s#@CKAN_SECRET@#${CKAN_KEY}#g" $CK_WEB_XML + +chown {{ smartgears_user }}:{{ smartgears_user }} $CK_WEB_XML +chmod 440 $CK_WEB_XML + +rm -f $SQL_FILE +touch $CK_WEB_DIR/.web.xml.configured + +{% endraw %} + + +exit 0 + + + diff --git a/smartgears/ckan_connector/templates/ckan-web.xml.j2 b/smartgears/ckan_connector/templates/ckan-web.xml.j2 new file mode 100644 index 0000000..a20ce21 --- /dev/null +++ b/smartgears/ckan_connector/templates/ckan-web.xml.j2 @@ -0,0 +1,29 @@ + + + secret + @CKAN_SECRET@ + + + hostIp + 0.0.0.0 + + + hostname + {{ ansible_fqdn }} + + + internalPort + {{ ckan_webapp_port }} + + + ckanKey + @CKAN_API_KEY@ + + + org.gcube.data.access.ckanconnector.CkanConnector + + + org.gcube.data.access.ckanconnector.CkanConnector + /* + +