From 4358e9fc3a6df7aac68b53c4eb8b2d47b33d0e1a Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Sat, 18 Jun 2016 16:06:16 +0200 Subject: [PATCH] library/roles/ckan: Split the role in 'ckan' and 'ckan-solr' because solr can run on a different host. --- ckan/ckan-solr/defaults/main.yml | 2 + ckan/{ => ckan-solr}/files/schema.xml | 0 ckan/ckan-solr/handlers/main.yml | 3 + ckan/ckan-solr/tasks/main.yml | 12 ++ ckan/{ => ckan}/defaults/main.yml | 0 ckan/{ => ckan}/files/base.py | 0 ckan/{ => ckan}/files/ckanharvester.py | 0 ckan/{ => ckan}/files/csw.py | 0 ckan/ckan/files/schema.xml | 187 ++++++++++++++++++ ckan/{ => ckan}/handlers/main.yml | 3 - .../main.yml => ckan/tasks/ckan-plugins.yml} | 76 ------- ckan/ckan/tasks/ckan.yml | 37 ++++ ckan/ckan/tasks/enable-ckan.yml | 11 ++ ckan/ckan/tasks/main.yml | 5 + ckan/ckan/tasks/supervisor.yml | 19 ++ .../templates/ckan_harvesting.conf.j2 | 0 .../{ => ckan}/templates/tracker_update.sh.j2 | 0 17 files changed, 276 insertions(+), 79 deletions(-) create mode 100644 ckan/ckan-solr/defaults/main.yml rename ckan/{ => ckan-solr}/files/schema.xml (100%) create mode 100644 ckan/ckan-solr/handlers/main.yml create mode 100644 ckan/ckan-solr/tasks/main.yml rename ckan/{ => ckan}/defaults/main.yml (100%) rename ckan/{ => ckan}/files/base.py (100%) rename ckan/{ => ckan}/files/ckanharvester.py (100%) rename ckan/{ => ckan}/files/csw.py (100%) create mode 100644 ckan/ckan/files/schema.xml rename ckan/{ => ckan}/handlers/main.yml (77%) rename ckan/{tasks/main.yml => ckan/tasks/ckan-plugins.yml} (65%) create mode 100644 ckan/ckan/tasks/ckan.yml create mode 100644 ckan/ckan/tasks/enable-ckan.yml create mode 100644 ckan/ckan/tasks/main.yml create mode 100644 ckan/ckan/tasks/supervisor.yml rename ckan/{ => ckan}/templates/ckan_harvesting.conf.j2 (100%) rename ckan/{ => ckan}/templates/tracker_update.sh.j2 (100%) diff --git a/ckan/ckan-solr/defaults/main.yml b/ckan/ckan-solr/defaults/main.yml new file mode 100644 index 0000000..655077c --- /dev/null +++ b/ckan/ckan-solr/defaults/main.yml @@ -0,0 +1,2 @@ +--- +ckan_solr_port: 8983 diff --git a/ckan/files/schema.xml b/ckan/ckan-solr/files/schema.xml similarity index 100% rename from ckan/files/schema.xml rename to ckan/ckan-solr/files/schema.xml diff --git a/ckan/ckan-solr/handlers/main.yml b/ckan/ckan-solr/handlers/main.yml new file mode 100644 index 0000000..be37064 --- /dev/null +++ b/ckan/ckan-solr/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Solr Restart + service: name=tomcat-instance-{{ ckan_solr_port }} state=restarted diff --git a/ckan/ckan-solr/tasks/main.yml b/ckan/ckan-solr/tasks/main.yml new file mode 100644 index 0000000..71738e0 --- /dev/null +++ b/ckan/ckan-solr/tasks/main.yml @@ -0,0 +1,12 @@ +--- +- name: Install the solr schema used by CKAN + file: src=/usr/lib/ckan/default/src/ckan/ckan/config/solr/schema.xml dest={{ tomcat_m_instances_base_path }}/{{ ckan_solr_port }}/solr/data/solr/collection1/conf/schema.xml state=link force=yes + when: not ckan_geonetwork_harvester + notify: Solr Restart + tags: [ 'ckan', 'solr', 'solr_schema' ] + +- name: Install the solr schema used by CKAN, modified with the spatial fields + copy: src=schema.xml dest={{ tomcat_m_instances_base_path }}/{{ ckan_solr_port }}/solr/data/solr/collection1/conf/schema.xml force=yes + when: ckan_geonetwork_harvester + notify: Solr Restart + tags: [ 'ckan', 'solr', 'solr_schema' ] diff --git a/ckan/defaults/main.yml b/ckan/ckan/defaults/main.yml similarity index 100% rename from ckan/defaults/main.yml rename to ckan/ckan/defaults/main.yml diff --git a/ckan/files/base.py b/ckan/ckan/files/base.py similarity index 100% rename from ckan/files/base.py rename to ckan/ckan/files/base.py diff --git a/ckan/files/ckanharvester.py b/ckan/ckan/files/ckanharvester.py similarity index 100% rename from ckan/files/ckanharvester.py rename to ckan/ckan/files/ckanharvester.py diff --git a/ckan/files/csw.py b/ckan/ckan/files/csw.py similarity index 100% rename from ckan/files/csw.py rename to ckan/ckan/files/csw.py diff --git a/ckan/ckan/files/schema.xml b/ckan/ckan/files/schema.xml new file mode 100644 index 0000000..6707914 --- /dev/null +++ b/ckan/ckan/files/schema.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +index_id +text + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ckan/handlers/main.yml b/ckan/ckan/handlers/main.yml similarity index 77% rename from ckan/handlers/main.yml rename to ckan/ckan/handlers/main.yml index addf260..d3d94cb 100644 --- a/ckan/handlers/main.yml +++ b/ckan/ckan/handlers/main.yml @@ -1,7 +1,4 @@ --- -- name: Solr Restart - service: name=tomcat-instance-{{ ckan_solr_port }} state=restarted - - name: Restart CKAN service: name=apache2 state=restarted sleep=10 diff --git a/ckan/tasks/main.yml b/ckan/ckan/tasks/ckan-plugins.yml similarity index 65% rename from ckan/tasks/main.yml rename to ckan/ckan/tasks/ckan-plugins.yml index 7da5237..1a5cf9a 100644 --- a/ckan/tasks/main.yml +++ b/ckan/ckan/tasks/ckan-plugins.yml @@ -1,52 +1,4 @@ --- -- name: Download the CKAN distribution - get_url: url='{{ ckan_package_url }}' dest=/srv/{{ ckan_deb_file }} - tags: ckan - -- name: Install the CKAN deb package - apt: deb=/srv/{{ ckan_deb_file }} - register: ckan_install - tags: ckan - -- name: Configure the CKAN production configuration file - ini_file: dest={{ ckan_config_file }} section={{ item.section }} option={{ item.option }} value={{ item.value }} state={{ item.state }} backup=yes - with_items: '{{ ckan_production_ini_opts }}' - notify: Restart CKAN - tags: [ 'ckan', 'ckan_ini' ] - -- name: Install the solr schema used by CKAN - file: src=/usr/lib/ckan/default/src/ckan/ckan/config/solr/schema.xml dest={{ tomcat_m_instances_base_path }}/{{ ckan_solr_port }}/solr/data/solr/collection1/conf/schema.xml state=link force=yes - when: not ckan_geonetwork_harvester - notify: Solr Restart - tags: [ 'ckan', 'solr', 'solr_schema' ] - -- name: Install the solr schema used by CKAN, modified with the spatial fields - copy: src=schema.xml dest={{ tomcat_m_instances_base_path }}/{{ ckan_solr_port }}/solr/data/solr/collection1/conf/schema.xml force=yes - when: ckan_geonetwork_harvester - notify: Solr Restart - tags: [ 'ckan', 'solr', 'solr_schema' ] - -- name: Create the base directory for the CKAN file storage - file: dest={{ ckan_file_storage_dir }} state=directory owner={{ apache_user }} mode=0700 - tags: ckan - -- name: Initialize the CKAN databases - shell: ckan db init ; ckan datastore set-permissions | su - postgres -c 'psql --set ON_ERROR_STOP=1' - when: ( ckan_install | changed ) - tags: ckan - -- name: Create the pip cache directory with the right permissions - file: dest={{ ckan_libdir }}/.cache owner={{ ckan_shell_user }} group={{ ckan_shell_user }} state=directory - tags: [ 'ckan', 'ckan_user' ] - -- name: Assign the CKAN virtenv dir to the ckan user - file: dest={{ ckan_virtenv }} recurse=yes owner={{ ckan_shell_user }} group={{ ckan_shell_user }} - tags: [ 'ckan', 'ckan_user' ] - -- name: Create a log directory for the jobs run by the ckan user - file: dest={{ ckan_logdir }} state=directory owner={{ ckan_shell_user }} group={{ ckan_shell_user }} - tags: [ 'ckan', 'ckan_user' ] - - name: Install some plugins dependencies inside the CKAN virtualenv become: True become_user: '{{ ckan_shell_user }}' @@ -190,31 +142,3 @@ # notify: Restart CKAN # tags: [ 'ckan', 'ckan_pages', 'ckan_plugins', 'ckan_ckanext_spatial' ] -- name: Install the supervisor daemon needed to automate the gather and fetch operations - apt: pkg={{ item }} state=present - with_items: '{{ ckan_gather_fetch_pkgs }}' - tags: [ 'ckan', 'ckan_harvest' ] - -- name: Install the gather and fetch supervisor configuration - template: src=ckan_harvesting.conf.j2 dest=/etc/supervisor/conf.d/ckan_harvesting.conf owner=root group=root mode=0644 - notify: Reconfigure the supervisor daemon - tags: [ 'ckan', 'ckan_harvest' ] - -- name: Install a cron job that - cron: name="CKAN harvester" minute="0" job="{{ ckan_virtenv }}/bin/paster --plugin=ckanext-harvest harvester run --config={{ ckan_config_file }} > {{ ckan_logdir }}/harvester_run.log 2>&1" user={{ ckan_shell_user }} - when: ckan_harvester_run - tags: [ 'ckan', 'ckan_harvest', 'ckan_harvest_cron' ] - -- name: Restart apache - service: name=apache state=restarted enabled=yes - when: ( ckan_install | changed ) - tags: ckan - -- name: Restart nginx - service: name=nginx state=restarted enabled=yes - when: ( ckan_install | changed ) - tags: ckan - -- name: Ensure that supervisord is running and enabled - service: name=supervisor state=started enabled=yes - tags: [ 'ckan', 'ckan_harvest' ] diff --git a/ckan/ckan/tasks/ckan.yml b/ckan/ckan/tasks/ckan.yml new file mode 100644 index 0000000..343b32d --- /dev/null +++ b/ckan/ckan/tasks/ckan.yml @@ -0,0 +1,37 @@ +--- +- name: Download the CKAN distribution + get_url: url='{{ ckan_package_url }}' dest=/srv/{{ ckan_deb_file }} + tags: ckan + +- name: Install the CKAN deb package + apt: deb=/srv/{{ ckan_deb_file }} + register: ckan_install + tags: ckan + +- name: Configure the CKAN production configuration file + ini_file: dest={{ ckan_config_file }} section={{ item.section }} option={{ item.option }} value={{ item.value }} state={{ item.state }} backup=yes + with_items: '{{ ckan_production_ini_opts }}' + notify: Restart CKAN + tags: [ 'ckan', 'ckan_ini' ] + +- name: Create the base directory for the CKAN file storage + file: dest={{ ckan_file_storage_dir }} state=directory owner={{ apache_user }} mode=0700 + tags: ckan + +- name: Initialize the CKAN databases + shell: ckan db init ; ckan datastore set-permissions | su - postgres -c 'psql --set ON_ERROR_STOP=1' + when: ( ckan_install | changed ) + tags: ckan + +- name: Create the pip cache directory with the right permissions + file: dest={{ ckan_libdir }}/.cache owner={{ ckan_shell_user }} group={{ ckan_shell_user }} state=directory + tags: [ 'ckan', 'ckan_user' ] + +- name: Assign the CKAN virtenv dir to the ckan user + file: dest={{ ckan_virtenv }} recurse=yes owner={{ ckan_shell_user }} group={{ ckan_shell_user }} + tags: [ 'ckan', 'ckan_user' ] + +- name: Create a log directory for the jobs run by the ckan user + file: dest={{ ckan_logdir }} state=directory owner={{ ckan_shell_user }} group={{ ckan_shell_user }} + tags: [ 'ckan', 'ckan_user' ] + diff --git a/ckan/ckan/tasks/enable-ckan.yml b/ckan/ckan/tasks/enable-ckan.yml new file mode 100644 index 0000000..7fe8e2d --- /dev/null +++ b/ckan/ckan/tasks/enable-ckan.yml @@ -0,0 +1,11 @@ +--- +- name: Restart apache + service: name=apache state=restarted enabled=yes + when: ( ckan_install | changed ) + tags: ckan + +- name: Restart nginx + service: name=nginx state=restarted enabled=yes + when: ( ckan_install | changed ) + tags: ckan + diff --git a/ckan/ckan/tasks/main.yml b/ckan/ckan/tasks/main.yml new file mode 100644 index 0000000..95db53d --- /dev/null +++ b/ckan/ckan/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- include: ckan.yml +- include: ckan-plugins.yml +- include: enable-ckan.yml +- include: supervisor.yml diff --git a/ckan/ckan/tasks/supervisor.yml b/ckan/ckan/tasks/supervisor.yml new file mode 100644 index 0000000..6d5a253 --- /dev/null +++ b/ckan/ckan/tasks/supervisor.yml @@ -0,0 +1,19 @@ +--- +- name: Install the supervisor daemon needed to automate the gather and fetch operations + apt: pkg={{ item }} state=present + with_items: '{{ ckan_gather_fetch_pkgs }}' + tags: [ 'ckan', 'ckan_harvest' ] + +- name: Install the gather and fetch supervisor configuration + template: src=ckan_harvesting.conf.j2 dest=/etc/supervisor/conf.d/ckan_harvesting.conf owner=root group=root mode=0644 + notify: Reconfigure the supervisor daemon + tags: [ 'ckan', 'ckan_harvest' ] + +- name: Install a cron job that run the harvesters + cron: name="CKAN harvester" minute="0" job="{{ ckan_virtenv }}/bin/paster --plugin=ckanext-harvest harvester run --config={{ ckan_config_file }} > {{ ckan_logdir }}/harvester_run.log 2>&1" user={{ ckan_shell_user }} + when: ckan_harvester_run + tags: [ 'ckan', 'ckan_harvest', 'ckan_harvest_cron' ] + +- name: Ensure that supervisord is running and enabled + service: name=supervisor state=started enabled=yes + tags: [ 'ckan', 'ckan_harvest' ] diff --git a/ckan/templates/ckan_harvesting.conf.j2 b/ckan/ckan/templates/ckan_harvesting.conf.j2 similarity index 100% rename from ckan/templates/ckan_harvesting.conf.j2 rename to ckan/ckan/templates/ckan_harvesting.conf.j2 diff --git a/ckan/templates/tracker_update.sh.j2 b/ckan/ckan/templates/tracker_update.sh.j2 similarity index 100% rename from ckan/templates/tracker_update.sh.j2 rename to ckan/ckan/templates/tracker_update.sh.j2