mirror of
https://bitbucket.org/atlassian/dc-deployments-automation.git
synced 2025-12-14 00:43:06 -06:00
DCD-224: Refactor of product installer role.
This commit is contained in:
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
- name: Converge
|
||||||
|
hosts: all
|
||||||
|
vars:
|
||||||
|
atl_product_family: "jira"
|
||||||
|
atl_product_edition: "jira-software"
|
||||||
|
atl_product_user: "jira"
|
||||||
|
atl_product_version: "latest"
|
||||||
|
roles:
|
||||||
|
- role: linux_common
|
||||||
|
- role: product_common
|
||||||
|
- role: product_install
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
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_downloaded(host):
|
||||||
|
verfile = host.file('/media/atl/jira/shared/jira-software.version')
|
||||||
|
assert verfile.exists
|
||||||
|
|
||||||
|
def test_symlink_created(host):
|
||||||
|
target = host.file('/opt/atlassian/jira-software/current')
|
||||||
|
assert target.exists
|
||||||
|
assert target.is_symlink
|
||||||
|
|
||||||
|
def test_unpacked(host):
|
||||||
|
verfile = host.file('/opt/atlassian/jira-software/current/bin/catalina.sh')
|
||||||
|
assert verfile.exists
|
||||||
|
|
||||||
|
def test_version_file_is_latest(host):
|
||||||
|
verfile = host.file('/media/atl/jira/shared/jira-software.version')
|
||||||
|
assert verfile.exists
|
||||||
|
|
||||||
|
upstream_fd = urllib.request.urlopen("https://s3.amazonaws.com/atlassian-software/releases/jira-software/latest")
|
||||||
|
upstream = upstream_fd.read()
|
||||||
|
|
||||||
|
assert verfile.content.decode("UTF-8").strip() == upstream.decode("UTF-8").strip()
|
||||||
|
|
||||||
|
def test_latest_is_downloaded(host):
|
||||||
|
upstream_fd = urllib.request.urlopen("https://s3.amazonaws.com/atlassian-software/releases/jira-software/latest")
|
||||||
|
upstream = upstream_fd.read().decode("UTF-8").strip()
|
||||||
|
|
||||||
|
installer = host.file('/opt/atlassian/tmp/jira-software.'+upstream+'.bin')
|
||||||
|
assert installer.exists
|
||||||
|
assert installer.user == 'root'
|
||||||
1
roles/product_install/tasks/bitbucket_extra_tasks.yml
Symbolic link
1
roles/product_install/tasks/bitbucket_extra_tasks.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
no_op.yml
|
||||||
1
roles/product_install/tasks/bitbucket_version_latest.yml
Symbolic link
1
roles/product_install/tasks/bitbucket_version_latest.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
product_version_latest.yml
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Check for existing version cache file
|
|
||||||
stat:
|
|
||||||
path: "{{ atl_product_version_cache }}"
|
|
||||||
register: cached
|
|
||||||
|
|
||||||
# Case: File exists, always use its value
|
|
||||||
- name: Use version for product version
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Read cached version from file
|
|
||||||
command: "cat {{ atl_product_version_cache }}"
|
|
||||||
register: atl_product_version_file
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Set the local var to cached version
|
|
||||||
set_fact:
|
|
||||||
atl_product_version: "{{ atl_product_version_file.stdout }}"
|
|
||||||
|
|
||||||
when: cached.stat.exists
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
# At this point atl_product_version should be set, cache if necessary.
|
|
||||||
- name: Write override cached version when specified
|
|
||||||
template:
|
|
||||||
src: version.j2
|
|
||||||
dest: "{{ atl_product_version_cache }}"
|
|
||||||
force: false
|
|
||||||
1
roles/product_install/tasks/confluence_extra_tasks.yml
Symbolic link
1
roles/product_install/tasks/confluence_extra_tasks.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
no_op.yml
|
||||||
1
roles/product_install/tasks/confluence_version_latest.yml
Symbolic link
1
roles/product_install/tasks/confluence_version_latest.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
product_version_latest.yml
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Create installation directories
|
|
||||||
file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: directory
|
|
||||||
mode: 0750
|
|
||||||
owner: "{{ atl_product_user }}"
|
|
||||||
group: "{{ atl_product_user }}"
|
|
||||||
with_items:
|
|
||||||
- "{{ atl_installer_temp }}"
|
|
||||||
- "{{ atl_product_home }}"
|
|
||||||
- "{{ atl_product_installation_versioned }}"
|
|
||||||
- "{{ atl_product_version_cache_dir }}"
|
|
||||||
changed_when: false # For Molecule idempotence check
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
# Note: We don't the cache binary in the shared drive to the complexity
|
|
||||||
# around download race-conditions if multiple nodes are starting at
|
|
||||||
# the same time. When downloading from product-downloads.atlassian.com
|
|
||||||
# (which is a CDN) takes seconds anyway.
|
|
||||||
- name: Fetch product installer
|
|
||||||
get_url:
|
|
||||||
url: "{{ atl_product_download_url }}"
|
|
||||||
dest: "{{ atl_product_download }}"
|
|
||||||
mode: 0755
|
|
||||||
force: false
|
|
||||||
|
|
||||||
- name: Create installer varfile
|
|
||||||
template:
|
|
||||||
src: "{{ atl_product_family }}.varfile.j2"
|
|
||||||
dest: "{{ atl_product_varfile }}"
|
|
||||||
mode: 0755
|
|
||||||
|
|
||||||
# NOTE: We run the installer as the user rather than root to limit its
|
|
||||||
# actions. For example, if root and the 'jira' user exists then it
|
|
||||||
# will create 'jira1'; this potentially creates idempotency/upgrade
|
|
||||||
# issues down the line.
|
|
||||||
- name: Run the installer
|
|
||||||
command: /bin/sh "{{ atl_product_download }}" -q -varfile "{{ atl_product_varfile }}"
|
|
||||||
args:
|
|
||||||
creates: "{{ atl_product_installation_versioned }}/.install4j/"
|
|
||||||
become: true
|
|
||||||
become_user: "{{ atl_product_user }}"
|
|
||||||
|
|
||||||
- name: Symlink the installed version to current
|
|
||||||
file:
|
|
||||||
src: "{{ atl_product_installation_versioned }}"
|
|
||||||
dest: "{{ atl_product_installation_current }}"
|
|
||||||
state: link
|
|
||||||
force: true
|
|
||||||
1
roles/product_install/tasks/jira-core_extra_tasks.yml
Symbolic link
1
roles/product_install/tasks/jira-core_extra_tasks.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
no_op.yml
|
||||||
1
roles/product_install/tasks/jira-core_version_latest.yml
Symbolic link
1
roles/product_install/tasks/jira-core_version_latest.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
product_version_latest.yml
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Set the download edition for ServiceDesk
|
||||||
|
set_fact:
|
||||||
|
atl_download_edition: "servicedesk"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: Fetch the ServiceDesk metadata from marketplace
|
||||||
|
set_fact:
|
||||||
|
atl_servicedesk_version_json: "{{ lookup('url', '{{ atl_servicedesk_latest_url }}') }}"
|
||||||
|
|
||||||
|
- name: Set the version for ServiceDesk
|
||||||
|
set_fact:
|
||||||
|
atl_product_version: "{{ atl_servicedesk_version_json.name }}"
|
||||||
1
roles/product_install/tasks/jira-software_extra_tasks.yml
Symbolic link
1
roles/product_install/tasks/jira-software_extra_tasks.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
no_op.yml
|
||||||
1
roles/product_install/tasks/jira-software_version_latest.yml
Symbolic link
1
roles/product_install/tasks/jira-software_version_latest.yml
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
product_version_latest.yml
|
||||||
@@ -1,14 +1,97 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
# Common case for most products and Jira editions.
|
- name: Create installation directories
|
||||||
- name: Fetch ServiceDesk metadata if necessary
|
file:
|
||||||
include_tasks: "servicedesk_download.yml"
|
path: "{{ item }}"
|
||||||
when: atl_product_edition == "jira-servicedesk"
|
state: directory
|
||||||
|
mode: 0750
|
||||||
|
owner: "{{ atl_product_user }}"
|
||||||
|
group: "{{ atl_product_user }}"
|
||||||
|
with_items:
|
||||||
|
- "{{ atl_installer_temp }}"
|
||||||
|
- "{{ atl_product_home }}"
|
||||||
|
- "{{ atl_product_installation_versioned }}"
|
||||||
|
- "{{ atl_product_version_cache_dir }}"
|
||||||
|
changed_when: false # For Molecule idempotence check
|
||||||
|
|
||||||
# Differences for ServiceDesk become fiddly enough that it's better to
|
|
||||||
# just split them out and move common functionality into individual
|
- name: Check for existing version cache file
|
||||||
# task files. This gives us some flexibility in the future if
|
stat:
|
||||||
# necessary.
|
path: "{{ atl_product_version_cache }}"
|
||||||
- name: Fetch product metadata if necessary
|
register: cached
|
||||||
include_tasks: "product_download.yml"
|
|
||||||
when: atl_product_edition != "jira-servicedesk"
|
# Case: File exists, always use its value
|
||||||
|
- name: Use version for product version
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: Read cached version from file
|
||||||
|
command: "cat {{ atl_product_version_cache }}"
|
||||||
|
register: atl_product_version_file
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Set the local var to cached version
|
||||||
|
set_fact:
|
||||||
|
atl_product_version: "{{ atl_product_version_file.stdout }}"
|
||||||
|
|
||||||
|
when: cached.stat.exists
|
||||||
|
|
||||||
|
|
||||||
|
# Case: File doesn't exist and no version has been set; find latest.
|
||||||
|
- name: Fetch and cache latest version when no override
|
||||||
|
block:
|
||||||
|
|
||||||
|
- name: Fetch the latest edition version
|
||||||
|
include_tasks: "{{ atl_product_edition }}_version_latest.yml"
|
||||||
|
|
||||||
|
when:
|
||||||
|
not cached.stat.exists and
|
||||||
|
(atl_product_version is undefined or
|
||||||
|
not atl_product_version or
|
||||||
|
atl_product_version == "latest")
|
||||||
|
|
||||||
|
|
||||||
|
- name: Perform any additional per-edition version setup
|
||||||
|
include_tasks: "{{ atl_product_edition }}_extra_tasks.yml"
|
||||||
|
|
||||||
|
|
||||||
|
# At this point atl_product_version should be set, cache if necessary.
|
||||||
|
- name: Write override cached version when specified
|
||||||
|
template:
|
||||||
|
src: version.j2
|
||||||
|
dest: "{{ atl_product_version_cache }}"
|
||||||
|
force: false
|
||||||
|
|
||||||
|
# Note: We don't the cache binary in the shared drive to the complexity
|
||||||
|
# around download race-conditions if multiple nodes are starting at
|
||||||
|
# the same time. When downloading from product-downloads.atlassian.com
|
||||||
|
# (which is a CDN) takes seconds anyway.
|
||||||
|
- name: Fetch product installer
|
||||||
|
get_url:
|
||||||
|
url: "{{ atl_product_download_url }}"
|
||||||
|
dest: "{{ atl_product_download }}"
|
||||||
|
mode: 0755
|
||||||
|
force: false
|
||||||
|
|
||||||
|
- name: Create installer varfile
|
||||||
|
template:
|
||||||
|
src: "{{ atl_product_family }}.varfile.j2"
|
||||||
|
dest: "{{ atl_product_varfile }}"
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
# NOTE: We run the installer as the user rather than root to limit its
|
||||||
|
# actions. For example, if root and the 'jira' user exists then it
|
||||||
|
# will create 'jira1'; this potentially creates idempotency/upgrade
|
||||||
|
# issues down the line.
|
||||||
|
- name: Run the installer
|
||||||
|
command: /bin/sh "{{ atl_product_download }}" -q -varfile "{{ atl_product_varfile }}"
|
||||||
|
args:
|
||||||
|
creates: "{{ atl_product_installation_versioned }}/.install4j/"
|
||||||
|
become: true
|
||||||
|
become_user: "{{ atl_product_user }}"
|
||||||
|
|
||||||
|
- name: Symlink the installed version to current
|
||||||
|
file:
|
||||||
|
src: "{{ atl_product_installation_versioned }}"
|
||||||
|
dest: "{{ atl_product_installation_current }}"
|
||||||
|
state: link
|
||||||
|
force: true
|
||||||
|
|||||||
1
roles/product_install/tasks/no_op.yml
Normal file
1
roles/product_install/tasks/no_op.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
---
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Create installation directories if necessary
|
|
||||||
include_tasks: "create_dirs.yml"
|
|
||||||
|
|
||||||
- name: Check for and load cached version
|
|
||||||
include_tasks: "cached_version_fetch.yml"
|
|
||||||
|
|
||||||
|
|
||||||
# Case: File doesn't exist and no version has been set; find latest.
|
|
||||||
- name: Fetch and cache latest version when no override
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Fetch the latest version from URL
|
|
||||||
set_fact:
|
|
||||||
atl_product_version_json: "{{ lookup('url', '{{ atl_product_latest_version_url }}') }}"
|
|
||||||
|
|
||||||
- name: Set the local var to retrieved version
|
|
||||||
set_fact:
|
|
||||||
atl_product_version: "{{ atl_product_version_json.version }}"
|
|
||||||
|
|
||||||
when:
|
|
||||||
not cached.stat.exists and
|
|
||||||
(atl_product_version is undefined or
|
|
||||||
not atl_product_version or
|
|
||||||
atl_product_version == "latest")
|
|
||||||
|
|
||||||
|
|
||||||
- name: Cache download version if necessary
|
|
||||||
include_tasks: "cached_version_write.yml"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Fetch and unpack the product distribution
|
|
||||||
include_tasks: "fetch_product.yml"
|
|
||||||
13
roles/product_install/tasks/product_version_latest.yml
Normal file
13
roles/product_install/tasks/product_version_latest.yml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# This is the process for most products (except ServiceDesk
|
||||||
|
# basically). Symlink this to <edition>_version_latest.yml for each
|
||||||
|
# product that supports the standard marketplace API.
|
||||||
|
|
||||||
|
- name: Fetch the latest version from URL
|
||||||
|
set_fact:
|
||||||
|
atl_product_version_json: "{{ lookup('url', '{{ atl_product_latest_version_url }}') }}"
|
||||||
|
|
||||||
|
- name: Set the local var to retrieved version
|
||||||
|
set_fact:
|
||||||
|
atl_product_version: "{{ atl_product_version_json.version }}"
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
|
|
||||||
- name: Create installation directories if necesary
|
|
||||||
include_tasks: "create_dirs.yml"
|
|
||||||
|
|
||||||
- name: Check for and load cached version
|
|
||||||
include_tasks: "cached_version_fetch.yml"
|
|
||||||
|
|
||||||
|
|
||||||
# Case: File doesn't exist and no version has been set; find latest.
|
|
||||||
- name: Fetch and cache latest version when no override
|
|
||||||
block:
|
|
||||||
|
|
||||||
- name: Fetch the ServiceDesk metadata from marketplace
|
|
||||||
set_fact:
|
|
||||||
atl_servicedesk_version_json: "{{ lookup('url', '{{ atl_servicedesk_latest_url }}') }}"
|
|
||||||
|
|
||||||
- name: Set the version for ServiceDesk
|
|
||||||
set_fact:
|
|
||||||
atl_product_version: "{{ atl_servicedesk_version_json.name }}"
|
|
||||||
|
|
||||||
when:
|
|
||||||
not cached.stat.exists and
|
|
||||||
(atl_product_version is undefined or
|
|
||||||
not atl_product_version or
|
|
||||||
atl_product_version == "latest")
|
|
||||||
|
|
||||||
- name: Cache download version if necessary
|
|
||||||
include_tasks: "cached_version_write.yml"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Set the download edition for ServiceDesk
|
|
||||||
set_fact:
|
|
||||||
atl_download_edition: "servicedesk"
|
|
||||||
|
|
||||||
- name: Fetch and unpack the product distribution
|
|
||||||
include_tasks: "fetch_product.yml"
|
|
||||||
Reference in New Issue
Block a user