From 83720dab179a29a9758a372879d26a632e2d8ae0 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 4 Aug 2016 17:50:37 +0200 Subject: [PATCH] library/roles/opencpu: Manage options customization. --- opencpu/defaults/main.yml | 4 ++++ opencpu/handlers/main.yml | 4 ++++ opencpu/tasks/main.yml | 27 +++++++++++++++++++++++- opencpu/templates/custom-opencpu.conf.j2 | 8 +++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 opencpu/handlers/main.yml create mode 100644 opencpu/templates/custom-opencpu.conf.j2 diff --git a/opencpu/defaults/main.yml b/opencpu/defaults/main.yml index 9d44bce7..04afad6b 100644 --- a/opencpu/defaults/main.yml +++ b/opencpu/defaults/main.yml @@ -2,6 +2,7 @@ # https://www.opencpu.org/download.html # It installs a local apache instance opencpu_install: True +opencpu_enabled: True opencpu_version: 1.5 opencpu_repo: 'ppa:opencpu/opencpu-{{ opencpu_version }}' opencpu_pkg_state: latest @@ -11,3 +12,6 @@ opencpu_pkgs: opencpu_proxy_port: 8004 opencpu_context: /ocpu +opencpu_options: + - { name: 'timelimit.get', value: '900' } + - { name: 'timelimit.post', value: '900' } diff --git a/opencpu/handlers/main.yml b/opencpu/handlers/main.yml new file mode 100644 index 00000000..529043b1 --- /dev/null +++ b/opencpu/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: restart opencpu + service: name=opencpu state=restarted + when: opencpu_enabled diff --git a/opencpu/tasks/main.yml b/opencpu/tasks/main.yml index ab8b91eb..c9b35ace 100644 --- a/opencpu/tasks/main.yml +++ b/opencpu/tasks/main.yml @@ -5,8 +5,33 @@ apt_repository: repo={{ opencpu_repo }} update_cache=yes - name: Install the opencpu package - apt: pkg={{ item }} state={{ opencpu_pkg_state }} + apt: pkg={{ item }} state={{ opencpu_pkg_state }} update_cache=yes cache_valid_time=3600 with_items: '{{ opencpu_pkgs }}' + - name: Install a custom opencpu configuration + template: src=custom-opencpu.conf.j2 dest=/etc/opencpu/server.conf.d/custom.conf owner=opencpu group=opencpu mode=0644 + notify: restart opencpu + + - name: Ensure that the opencpu service is enabled and running + service: name=opencpu state=started enabled=yes + when: opencpu_enabled + + - name: Ensure that the opencpu service is disabled and stopped + service: name=opencpu state=stopped enabled=no + when: not opencpu_enabled + tags: opencpu when: opencpu_install + + +- block: + + - name: Remove the opencpu repository + apt_repository: repo={{ opencpu_repo }} state=absent + + - name: Remove the opencpu package + apt: pkg={{ item }} state=absent + with_items: '{{ opencpu_pkgs }}' + + tags: opencpu + when: not opencpu_install diff --git a/opencpu/templates/custom-opencpu.conf.j2 b/opencpu/templates/custom-opencpu.conf.j2 new file mode 100644 index 00000000..c31702e6 --- /dev/null +++ b/opencpu/templates/custom-opencpu.conf.j2 @@ -0,0 +1,8 @@ +{ + +{% for opt in opencpu_options %} + "{{ opt.name }}": {{ opt.value }}{% if not loop.last %},{% endif %} + +{% endfor %} + +}