From e32b439ce2baaf3f48a76db108581d9c858925f1 Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Mon, 29 Apr 2019 15:37:44 +1000 Subject: [PATCH] DCD-224: Add installation of the ServiceDesk OBR when specified version is "all" or "servicedesk". --- aws_jira_dc_node.yml | 12 +++++- group_vars/aws_node_local.yml | 1 + roles/jira_config/.yamllint | 1 + roles/jira_config/defaults/main.yml | 3 ++ .../molecule/servicedesk/Dockerfile.j2 | 14 +++++++ .../molecule/servicedesk/molecule.yml | 30 ++++++++++++++ .../molecule/servicedesk/playbook.yml | 24 +++++++++++ .../servicedesk/tests/test_default.py | 26 ++++++++++++ roles/jira_config/tasks/main.yml | 41 +++++++++++++++++++ roles/linux_common/tasks/main.yml | 1 + roles/product_common/tasks/main.yml | 2 + 11 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 roles/jira_config/molecule/servicedesk/Dockerfile.j2 create mode 100644 roles/jira_config/molecule/servicedesk/molecule.yml create mode 100644 roles/jira_config/molecule/servicedesk/playbook.yml create mode 100644 roles/jira_config/molecule/servicedesk/tests/test_default.py diff --git a/aws_jira_dc_node.yml b/aws_jira_dc_node.yml index 20fb0c4..b329b1a 100644 --- a/aws_jira_dc_node.yml +++ b/aws_jira_dc_node.yml @@ -4,9 +4,19 @@ vars: atl_product_family: "jira" - atl_product_edition: "jira-{{ lookup('env', 'ATL_PRODUCT_EDITION') | lower }}" atl_product_user: "jira" + # FIXME: Slightly hacky workaround for specifying All or + # ServiceDesk; override to use Software and install plugins later. + atl_product_bundle: "{{ lookup('env', 'ATL_PRODUCT_EDITION') | lower }}" + bundle_map: + all: software + servicedesk: software + core: core + software: software + + atl_product_edition: "jira-{{ bundle_map[atl_product_bundle] }}" + roles: - linux_common - aws_common diff --git a/group_vars/aws_node_local.yml b/group_vars/aws_node_local.yml index 01b4b7a..18b9c3a 100644 --- a/group_vars/aws_node_local.yml +++ b/group_vars/aws_node_local.yml @@ -18,6 +18,7 @@ atl_shared_mountpoint: "/media/atl" atl_home_base: "/var/atlassian/application-data" atl_product_home: "{{ atl_home_base }}/{{ atl_product_family }}" atl_product_home_shared: "{{ atl_shared_mountpoint }}/{{ atl_product_family }}/shared" +atl_product_shared_plugins: "{{ atl_product_home_shared }}/plugins/installed-plugins" atl_installation_base: "/opt/atlassian" atl_product_installation_base: "{{ atl_installation_base }}/{{ atl_product_edition }}" diff --git a/roles/jira_config/.yamllint b/roles/jira_config/.yamllint index ad0be76..a87f8ff 100644 --- a/roles/jira_config/.yamllint +++ b/roles/jira_config/.yamllint @@ -9,3 +9,4 @@ rules: level: error line-length: disable truthy: disable + trailing-spaces: false diff --git a/roles/jira_config/defaults/main.yml b/roles/jira_config/defaults/main.yml index 02f6366..82df4a9 100644 --- a/roles/jira_config/defaults/main.yml +++ b/roles/jira_config/defaults/main.yml @@ -24,3 +24,6 @@ atl_tomcat_protocol: "HTTP/1.1" atl_tomcat_redirectport: "" atl_tomcat_scheme: "http" atl_tomcat_secure: "false" + +atl_servicedesk_latest_version_url: "https://marketplace.atlassian.com/rest/2/products/key/jira-servicedesk/versions/latest" +atl_servicedesk_download_file: "{{ atl_installer_temp }}/jira-servicedesk-{{ atl_servicedesk_version }}.obr" diff --git a/roles/jira_config/molecule/servicedesk/Dockerfile.j2 b/roles/jira_config/molecule/servicedesk/Dockerfile.j2 new file mode 100644 index 0000000..e6aa95d --- /dev/null +++ b/roles/jira_config/molecule/servicedesk/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/roles/jira_config/molecule/servicedesk/molecule.yml b/roles/jira_config/molecule/servicedesk/molecule.yml new file mode 100644 index 0000000..7fd3163 --- /dev/null +++ b/roles/jira_config/molecule/servicedesk/molecule.yml @@ -0,0 +1,30 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: amazon_linux2 + image: amazonlinux:2 + groups: + - aws_node_local + - name: ubuntu_lts + image: ubuntu:bionic + groups: + - aws_node_local +provisioner: + name: ansible + options: + skip-tags: runtime_pkg + lint: + name: ansible-lint + inventory: + links: + group_vars: ../../../../group_vars/ +verifier: + name: testinfra + lint: + name: flake8 + enabled: false diff --git a/roles/jira_config/molecule/servicedesk/playbook.yml b/roles/jira_config/molecule/servicedesk/playbook.yml new file mode 100644 index 0000000..2f62713 --- /dev/null +++ b/roles/jira_config/molecule/servicedesk/playbook.yml @@ -0,0 +1,24 @@ +--- +- name: Converge + hosts: all + vars: + atl_product_bundle: servicedesk + bundle_map: + all: software + servicedesk: software + core: core + software: software + + atl_product_edition: "jira-{{ bundle_map[atl_product_bundle] }}" + atl_product_family: "jira" + atl_product_user: "jira" + + atl_jdbc_user: 'atljira' + atl_jvm_heap: 'PLACEHOLDER' + atl_cluster_node_id: 'FAKEID' + + roles: + - role: linux_common + - role: product_common + - role: product_download + - role: jira_config diff --git a/roles/jira_config/molecule/servicedesk/tests/test_default.py b/roles/jira_config/molecule/servicedesk/tests/test_default.py new file mode 100644 index 0000000..fdcf557 --- /dev/null +++ b/roles/jira_config/molecule/servicedesk/tests/test_default.py @@ -0,0 +1,26 @@ +import os +import urllib.request + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_version_is_correct(host): + verfile = host.file('/media/atl/jira/shared/jira-software.version') + assert verfile.exists + + assert verfile.content.decode("UTF-8").strip() == "8.1.0" + +def test_is_downloaded(host): + installer = host.file('/opt/atlassian/tmp/jira-software.8.1.0.tar.gz') + assert installer.exists + assert installer.user == 'root' + +def test_is_unpacked(host): + installer = host.file('/opt/atlassian/jira-software/8.1.0') + assert installer.exists + assert installer.is_directory + assert installer.user == 'jira' + assert installer.mode == 0o0755 diff --git a/roles/jira_config/tasks/main.yml b/roles/jira_config/tasks/main.yml index 96de31e..744b037 100644 --- a/roles/jira_config/tasks/main.yml +++ b/roles/jira_config/tasks/main.yml @@ -27,3 +27,44 @@ with_items: - 'JVM_MINIMUM_MEMORY' - 'JVM_MAXIMUM_MEMORY' + + +# FIXME: The following is a bit of a special-case for now; ideally we +# should convert this into a general plugin-installation task +# (esp. when we get to supporting Portfolio), but there's no use for ATM. +- name: Install ServiceDesk if required + block: + + - name: Fetch the latest version data + set_fact: + atl_servicedesk_version_json: "{{ lookup('url', '{{ atl_servicedesk_latest_version_url }}') }}" + - name: Extract the latest version number + set_fact: + atl_servicedesk_version: "{{ atl_servicedesk_version_json.name }}" + - name: Extract the download url + set_fact: + atl_servicedesk_download_url: "{{ atl_servicedesk_version_json._embedded.artifact._links.binary.href }}" + + - name: Download ServiceDesk + get_url: + url: "{{ atl_servicedesk_download_url }}" + dest: "{{ atl_servicedesk_download_file }}" + mode: 0640 + force: false + + - name: Extract the plugin to the shared plugin directory + command: /usr/bin/unzip -jn "{{ atl_servicedesk_download_file }}" "*.jar" + args: + chdir: "{{ atl_product_shared_plugins }}" + creates: "{{ atl_product_shared_plugins }}/*servicedesk*.jar" + warn: false + + - name: Make plugins writable by the Jira user + file: + path: "{{ atl_product_shared_plugins }}" + owner: "{{ atl_product_user }}" + group: "{{ atl_product_user }}" + mode: 0750 + recurse: true + + when: atl_product_bundle == "servicedesk" or atl_product_bundle == "all" diff --git a/roles/linux_common/tasks/main.yml b/roles/linux_common/tasks/main.yml index 84bd5d5..d7df2ee 100644 --- a/roles/linux_common/tasks/main.yml +++ b/roles/linux_common/tasks/main.yml @@ -11,5 +11,6 @@ - jq - tar - curl + - unzip - fontconfig - python-psycopg2 diff --git a/roles/product_common/tasks/main.yml b/roles/product_common/tasks/main.yml index e71d266..2a3e6ad 100644 --- a/roles/product_common/tasks/main.yml +++ b/roles/product_common/tasks/main.yml @@ -14,8 +14,10 @@ state: directory mode: 0750 owner: "{{ atl_product_user }}" + group: "{{ atl_product_user }}" with_items: - "{{ atl_product_home }}" - "{{ atl_installer_temp }}" - "{{ atl_product_home_shared }}" + - "{{ atl_product_shared_plugins }}" - "{{ atl_product_installation_base }}"