forked from ISTI-ansible-roles/ansible-roles
library/roles/ckan, library/roles/smartgears/ckan_connector: Now it is possible to choose to not initialize the database and create the admin user.
This commit is contained in:
parent
49217d527a
commit
ad08241d76
|
@ -25,6 +25,9 @@ ckan_logdir: /var/log/ckan
|
||||||
ckan_db_name: ckan
|
ckan_db_name: ckan
|
||||||
ckan_db_user: ckan
|
ckan_db_user: ckan
|
||||||
|
|
||||||
|
# By default, initialize the db and solr. Disable if you want to reinstall and maintain the old data
|
||||||
|
ckan_init_db_and_solr: True
|
||||||
|
|
||||||
# CKAN plugins
|
# CKAN plugins
|
||||||
ckan_plugins_state: latest
|
ckan_plugins_state: latest
|
||||||
# Order is important
|
# Order is important
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
args:
|
args:
|
||||||
creates: '{{ ckan_libdir }}/.ckan_db_initialized'
|
creates: '{{ ckan_libdir }}/.ckan_db_initialized'
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
|
when: ckan_init_db_and_solr
|
||||||
tags: ckan
|
tags: ckan
|
||||||
|
|
||||||
- name: Create the pip cache directory with the right permissions
|
- name: Create the pip cache directory with the right permissions
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
---
|
---
|
||||||
- block:
|
- block:
|
||||||
|
|
||||||
- name: Remove the installed CKAN connector before upgrading
|
- name: Remove the installed CKAN connector before upgrading
|
||||||
file: dest={{ item }} state=absent
|
file: dest={{ item }} state=absent
|
||||||
with_items:
|
with_items:
|
||||||
|
@ -25,7 +24,7 @@
|
||||||
|
|
||||||
- name: Fix the CKAN connector web.xml
|
- name: Fix the CKAN connector web.xml
|
||||||
become: False
|
become: False
|
||||||
shell: /usr/local/bin/ckan-connector-fixer
|
shell: /usr/local/bin/ckan-connector-fixer init
|
||||||
args:
|
args:
|
||||||
creates: '{{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF/.web.xml.configured'
|
creates: '{{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF/.web.xml.configured'
|
||||||
notify: Restart smartgears
|
notify: Restart smartgears
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -ne 1 ] ; then
|
||||||
|
logger 'ckan-connector-fixer: at least one argument must be passed'
|
||||||
|
echo "at leas one argument must be passed, init or update"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ARG=$1
|
||||||
CK_WEB_DIR={{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF
|
CK_WEB_DIR={{ smartgears_instance_path }}/webapps/ckan-connector/WEB-INF
|
||||||
CK_WEB_XML=$CK_WEB_DIR/.web.xml.tpl
|
CK_WEB_XML=$CK_WEB_DIR/.web.xml.tpl
|
||||||
CK_WEB_XML_TMP=$CK_WEB_DIR/.web.xml.tmp
|
CK_WEB_XML_TMP=$CK_WEB_DIR/.web.xml.tmp
|
||||||
|
@ -13,20 +20,43 @@ CK_INI=/etc/ckan/default/production.ini
|
||||||
API_KEY=
|
API_KEY=
|
||||||
CKAN_KEY=
|
CKAN_KEY=
|
||||||
SQL_FILE=$( mktemp /tmp/XXXXXX.sql )
|
SQL_FILE=$( mktemp /tmp/XXXXXX.sql )
|
||||||
|
CKAN_CREATE_USER={{ ckan_init_db_and_solr }}
|
||||||
|
|
||||||
|
trap "logger 'ckan-connector-fixer: trap intercepted, exiting.' ; cleanup" SIGHUP SIGINT SIGTERM
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
rm -f $SQL_FILE
|
||||||
|
rm -f $CK_WEB_XML_TMP
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if [ -f $CK_WEB_DIR/.web.xml.configured ] ; then
|
||||||
|
if [ "$ARG" != "update" ] ; then
|
||||||
|
logger 'ckan-connector-fixer: service already configured, doing nothing.'
|
||||||
|
echo "service already configured. Use 'update' as argument to force the execution"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
{% raw %}
|
{% raw %}
|
||||||
|
|
||||||
# Set the CKAN python virtualenv
|
# Set the CKAN python virtualenv
|
||||||
. /usr/lib/ckan/default/bin/activate
|
. /usr/lib/ckan/default/bin/activate
|
||||||
cd /usr/lib/ckan/default/src/ckan
|
cd /usr/lib/ckan/default/src/ckan
|
||||||
|
|
||||||
|
if [ "$CKAN_CREATE_USER" == "True" ] ; then
|
||||||
# Create the admin user
|
# Create the admin user
|
||||||
paster sysadmin add $CK_ADMIN -c $CK_INI << EOF
|
paster sysadmin add $CK_ADMIN -c $CK_INI << EOF
|
||||||
|
|
||||||
y
|
y
|
||||||
$CK_ADMIN_PWD
|
$CK_ADMIN_PWD
|
||||||
$CK_ADMIN_PWD
|
$CK_ADMIN_PWD
|
||||||
|
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the admin key
|
# Get the admin key
|
||||||
echo "update \"user\" set state = 'active' where name = '${CK_ADMIN}';" > $SQL_FILE
|
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
|
echo "select apikey from \"user\" where name = '${CK_ADMIN}' and state = 'active';" >> $SQL_FILE
|
||||||
|
@ -59,10 +89,9 @@ mv $CK_WEB_XML_TMP $CK_WEB_XML_DEST
|
||||||
chown {{ smartgears_user }}:{{ smartgears_user }} $CK_WEB_XML_DEST
|
chown {{ smartgears_user }}:{{ smartgears_user }} $CK_WEB_XML_DEST
|
||||||
chmod 440 $CK_WEB_XML_DEST
|
chmod 440 $CK_WEB_XML_DEST
|
||||||
|
|
||||||
rm -f $SQL_FILE
|
|
||||||
touch $CK_WEB_DIR/.web.xml.configured
|
touch $CK_WEB_DIR/.web.xml.configured
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue