From 755b37c5fe313b50fd0154e8bbb7ce2f11eb4141 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 1 Jun 2020 13:16:13 +0200 Subject: [PATCH] The OpenRefine role has its own repository. --- README.md | 29 ++++++-------- defaults/main.yml | 21 +++++++++- handlers/main.yml | 4 +- meta/main.yml | 68 +++++++++------------------------ tasks/main.yml | 65 ++++++++++++++++++++++++++++++- templates/openrefine.conf.j2 | 13 +++++++ templates/openrefine.service.j2 | 18 +++++++++ templates/refine.ini.j2 | 25 ++++++++++++ 8 files changed, 173 insertions(+), 70 deletions(-) create mode 100644 templates/openrefine.conf.j2 create mode 100644 templates/openrefine.service.j2 create mode 100644 templates/refine.ini.j2 diff --git a/README.md b/README.md index 3637db8..0b60cde 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,24 @@ Role Name ========= -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +Role that installs OpenRefine. +OpenRefine is a free, open source power tool for working with messy data and improving it. Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +The list of extensions + +``` yaml +openrefine_extensions: + - { url: 'https://github.com/FAIRDataTeam/OpenRefine-metadata-extension/releases/download/v1.4.0/metadata-1.4.0-OpenRefine-3.3.tgz', name: 'metadata' } + - { url: 'https://github.com/stkenny/grefine-rdf-extension/releases/download/v1.2.0-orefine-3.3/rdf-extension-1.2.0-orefine-3.3.zip', name: 'rdf' } +``` Dependencies ------------ -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +openjdk License ------- @@ -35,4 +28,4 @@ EUPL-1.2 Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +Andrea Dell'Amico, diff --git a/defaults/main.yml b/defaults/main.yml index 95d3c70..29d5b36 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,21 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +openrefine_enabled: True +openrefine_major_version: 3 +openrefine_minor_version: 3 +openrefine_file_extension: 'tar.gz' +openrefine_distribution_prefix: 'openrefine' +openrefine_dist_file: '{{ openrefine_distribution_prefix }}-linux-{{ openrefine_version }}.{{ openrefine_file_extension }}' +openrefine_version: '{{ openrefine_major_version }}.{{ openrefine_minor_version }}' +openrefine_download_url: 'https://github.com/OpenRefine/OpenRefine/releases/download/{{ openrefine_version }}/{{ openrefine_dist_file }}' +openrefine_user: openrefine +openrefine_user_home: /srv/openrefine +openrefine_data_dir: '{{ openrefine_user_home }}/data' +openrefine_log_dir: '{{ openrefine_user_home }}/logs' +openrefine_base_dir: '{{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}' +openrefine_listen_ip: 127.0.0.1 +openrefine_http_port: 3333 +openrefine_memory: 4192M + +openrefine_extensions: [] +# - { url: 'https://github.com/FAIRDataTeam/OpenRefine-metadata-extension/releases/download/v1.4.0/metadata-1.4.0-OpenRefine-3.3.tgz', name: 'metadata' } +# - { url: 'https://github.com/stkenny/grefine-rdf-extension/releases/download/v1.2.0-orefine-3.3/rdf-extension-1.2.0-orefine-3.3.zip', name: 'rdf' } diff --git a/handlers/main.yml b/handlers/main.yml index 27474e0..d1ceb16 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,4 @@ --- -# handlers file for ansible-role-template \ No newline at end of file +- name: Restart openrefine + service: name=openrefine state=restarted + diff --git a/meta/main.yml b/meta/main.yml index 1126a5e..880518f 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,61 +1,31 @@ galaxy_info: - author: your name - description: your description + author: Andrea Dell'Amico + description: Systems Architect company: ISTI-CNR - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: EUPL-1.2 + license: EUPL 1.2+ min_ansible_version: 2.8 - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. # To view available platforms and versions (or releases), visit: # https://galaxy.ansible.com/api/v1/platforms/ # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 - - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. - -dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. + platforms: + - name: Ubuntu + versions: + - bionic + - name: EL + versions: + - 7 + - 8 + galaxy_tags: + - openrefine + +dependencies: + - src: git+https://gitea-s2i2s.isti.cnr.it/ISTI-ansible-roles/ansible-role-openjdk.git + version: master + name: openjdk + state: latest diff --git a/tasks/main.yml b/tasks/main.yml index 53c6cae..37e41bf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,65 @@ --- -# tasks file for ansible-role-template \ No newline at end of file +- block: + - name: Create the openrefine user + user: name={{ openrefine_user }} home={{ openrefine_user_home }} createhome=no shell=/usr/sbin/nologin system=yes + + - name: Create the openrefine home, if it does not already exist. + file: dest={{ openrefine_user_home }} owner=root group=root state=directory recurse=yes + + - name: Create the openrefine data and logs directories + file: dest={{ item }} owner={{ openrefine_user }} group={{ openrefine_user }} state=directory recurse=yes + with_items: + - '{{ openrefine_data_dir }}' + - '{{ openrefine_log_dir }}' + + - name: Download openrefine + unarchive: remote_src=yes src={{ openrefine_download_url }} dest={{ openrefine_user_home }} + args: + creates: '{{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}' + + - name: Install the openrefine configuration + template: src=refine.ini dest={{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}/refine.ini owner=root group=root mode=0644 + notify: Restart openrefine + tags: [ 'openrefine', 'google_openrefine', 'openrefine_conf' ] + + - name: Install the openrefine upstart init script + template: src=openrefine.conf.j2 dest=/etc/init/openrefine.conf owner=root group=root mode=0644 + when: ansible_service_mgr != 'systemd' + + - name: Install the OpenRefine systemd unit + template: src=openrefine.service.j2 dest=/lib/systemd/system/openrefine.service owner=root group=root mode=0644 + register: openrefine_unit_install + + - name: Reload the systemd configuration + systemd: daemon_reload=yes + when: openrefine_unit_install is changed + + - name: Ensure that the service is running and enabled + service: name=openrefine state=started enabled=yes + + when: openrefine_enabled + tags: [ 'openrefine', 'google_openrefine' ] + +- block: + + - name: Ensure that the service is running and enabled + service: name=openrefine state=stopped enabled=no + + when: not openrefine_enabled + tags: [ 'openrefine', 'google_openrefine' ] + +- name: Manage OpenRefine extensions + block: + - name: Create the openrefine modules dest directory + file: dest={{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}/webapp/extensions/{{ item.name }} state=directory + with_items: '{{ openrefine_extensions }}' + + - name: Download and unpack the openrefine modules + unarchive: src={{ item.url }} remote_src=yes dest={{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}/webapp/extensions/{{ item.name }} + with_items: '{{ openrefine_extensions }}' + args: + creates: '{{ openrefine_user_home }}/{{ openrefine_distribution_prefix }}-{{ openrefine_version }}/webapp/extensions/{{ item.name }}/module' + notify: Restart openrefine + + when: openrefine_enabled + tags: [ 'openrefine', 'google_openrefine', 'openrefine_extensions' ] diff --git a/templates/openrefine.conf.j2 b/templates/openrefine.conf.j2 new file mode 100644 index 0000000..1995ee3 --- /dev/null +++ b/templates/openrefine.conf.j2 @@ -0,0 +1,13 @@ +description "Google OpenRefine server" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +respawn limit 10 5 +setuid {{ openrefine_user }} +setgid {{ openrefine_user }} + +script + chdir {{ openrefine_base_dir }} + exec ./refine > {{ openrefine_log_dir }}/openrefine.log 2>&1 +end script diff --git a/templates/openrefine.service.j2 b/templates/openrefine.service.j2 new file mode 100644 index 0000000..05a76f3 --- /dev/null +++ b/templates/openrefine.service.j2 @@ -0,0 +1,18 @@ +[Unit] +Description=OpenRefine +After=network.target +Documentation=https://openrefine.org/ + +[Service] +WorkingDirectory={{ openrefine_base_dir }} +User={{ openrefine_user }} +Group={{ openrefine_user }} +ExecStart={{ openrefine_base_dir }} -i {{ openrefine_listen_ip }} +NoNewPrivileges=yes +Type=forking +TimeoutStopSec=3600s +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/templates/refine.ini.j2 b/templates/refine.ini.j2 new file mode 100644 index 0000000..d64e04f --- /dev/null +++ b/templates/refine.ini.j2 @@ -0,0 +1,25 @@ +# NOTE: This file is not read if you run the Refine executable directly +# It is only read of you use the refine shell script or refine.bat + +no_proxy="localhost,127.0.0.1" +REFINE_PORT={{ openrefine_http_port }} +#REFINE_HOST=127.0.0.1 +#REFINE_WEBAPP=main\webapp + +# Memory and max form size allocations +#REFINE_MAX_FORM_CONTENT_SIZE=1048576 +REFINE_MEMORY={{ openrefine_memory }} + +# Set initial java heap space (default: 256M) for better performance with large datasets +REFINE_MIN_MEMORY={{ openrefine_memory }} + +# Some sample configurations. These have no defaults. +#ANT_HOME=C:\grefine\tools\apache-ant-1.8.1 +#JAVA_HOME=C:\Program Files\Java\jdk1.8.0_151 +#JAVA_OPTIONS=-XX:+UseParallelGC -verbose:gc -Drefine.headless=true +#JAVA_OPTIONS=-Drefine.data_dir=C:\Users\user\AppData\Roaming\OpenRefine +JAVA_HOME={{ jdk_java_home }} +JAVA_OPTIONS="-server -Djava.awt.headless=true -Dfile.encoding=UTF-8" + +# Uncomment to increase autosave period to 60 mins (default: 5 minutes) for better performance of long-lasting transformations +#REFINE_AUTOSAVE_PERIOD=60