library/roles/smartgears/ckan_connector: Role that installs and configures a ckan-connector service.

d4science-ghn-cluster: Add the ckan-connector variables to the ckan production services.
This commit is contained in:
Andrea Dell'Amico 2016-06-24 18:42:41 +02:00
parent f0fb4584df
commit 44b444fdc0
6 changed files with 126 additions and 4 deletions

View File

@ -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

View File

@ -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

Binary file not shown.

View File

@ -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' ]

View File

@ -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

View File

@ -0,0 +1,29 @@
<web-app>
<context-param>
<param-name>secret</param-name>
<param-value>@CKAN_SECRET@</param-value>
</context-param>
<context-param>
<param-name>hostIp</param-name>
<param-value>0.0.0.0</param-value>
</context-param>
<context-param>
<param-name>hostname</param-name>
<param-value>{{ ansible_fqdn }}</param-value>
</context-param>
<context-param>
<param-name>internalPort</param-name>
<param-value>{{ ckan_webapp_port }}</param-value>
</context-param>
<context-param>
<param-name>ckanKey</param-name>
<param-value>@CKAN_API_KEY@</param-value>
</context-param>
<servlet>
<servlet-name>org.gcube.data.access.ckanconnector.CkanConnector</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>org.gcube.data.access.ckanconnector.CkanConnector</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>