73 lines
2.4 KiB
YAML
73 lines
2.4 KiB
YAML
---
|
|
- name: CLI | Check whether the binary is already present
|
|
ansible.builtin.stat:
|
|
path: "{{ _multica_bin }}"
|
|
register: _multica_cli_stat
|
|
check_mode: false
|
|
|
|
- name: CLI | Read the installed version
|
|
ansible.builtin.command:
|
|
argv: ["{{ _multica_bin }}", "--version"]
|
|
register: _multica_cli_installed
|
|
when: _multica_cli_stat.stat.exists
|
|
changed_when: false
|
|
failed_when: false
|
|
check_mode: false
|
|
|
|
# `multica --version` prints e.g. "multica 0.6.5 (commit: ..., built: ...)".
|
|
- name: CLI | Extract the installed version string
|
|
ansible.builtin.set_fact:
|
|
_multica_cli_version_found: >-
|
|
{{ ((_multica_cli_installed.stdout_lines | default([]) | first | default('')).split() + ['', ''])[1]
|
|
if (_multica_cli_installed.rc | default(1)) == 0 else '' }}
|
|
|
|
- name: CLI | Decide whether an install is needed
|
|
ansible.builtin.set_fact:
|
|
_multica_cli_needs_install: "{{ (_multica_cli_version_found | trim) != multica_version }}"
|
|
|
|
- name: CLI | Install the pinned release
|
|
when: _multica_cli_needs_install | bool
|
|
block:
|
|
- name: CLI | Create a staging directory
|
|
ansible.builtin.tempfile:
|
|
state: directory
|
|
suffix: multica-cli
|
|
register: _multica_stage
|
|
become: true
|
|
|
|
- name: CLI | Download the release tarball
|
|
ansible.builtin.get_url:
|
|
url: "{{ _multica_release_url }}"
|
|
dest: "{{ _multica_stage.path }}/{{ _multica_tarball }}"
|
|
checksum: "{{ ('sha256:' ~ _multica_checksums_url) if multica_verify_checksum | bool else omit }}"
|
|
mode: "0644"
|
|
become: true
|
|
|
|
- name: CLI | Unpack the binary
|
|
ansible.builtin.unarchive:
|
|
src: "{{ _multica_stage.path }}/{{ _multica_tarball }}"
|
|
dest: "{{ _multica_stage.path }}"
|
|
remote_src: true
|
|
become: true
|
|
|
|
# Replacing the binary while the daemon runs is fine — the handler restarts
|
|
# it, and the daemon also watches its own binary for version changes.
|
|
- name: CLI | Install it onto the PATH
|
|
ansible.builtin.copy:
|
|
src: "{{ _multica_stage.path }}/multica"
|
|
dest: "{{ _multica_bin }}"
|
|
remote_src: true
|
|
owner: root
|
|
group: root
|
|
mode: "0755"
|
|
become: true
|
|
notify: restart multica daemon
|
|
|
|
always:
|
|
- name: CLI | Remove the staging directory
|
|
ansible.builtin.file:
|
|
path: "{{ _multica_stage.path }}"
|
|
state: absent
|
|
become: true
|
|
when: _multica_stage.path is defined
|