74 lines
2.9 KiB
YAML
74 lines
2.9 KiB
YAML
---
|
|
# task/cni_install file for hashicorp_nomad
|
|
- name: "Get release for cni_plugins:{{ hashi_nomad_cni_plugins_version }}"
|
|
vars:
|
|
_cni_plugins_url_ext: "{% if hashi_nomad_cni_plugins_version == 'latest'%}releases{% else %}releases/tags{% endif %}"
|
|
ansible.builtin.uri:
|
|
url: "{{ hashi_nomad_cni_plugins_github_api }}/{{ _cni_plugins_url_ext }}/{{ hashi_nomad_cni_plugins_version }}"
|
|
return_content: true
|
|
register: _cni_plugins_new_release
|
|
|
|
- name: "Check if cni plugin is already installed"
|
|
ansible.builtin.stat:
|
|
path: "{{ hashi_nomad_cni_plugins_install_path }}/version"
|
|
changed_when: false
|
|
check_mode: false
|
|
register: _cni_plugins_is_installed
|
|
|
|
- name: "Check current cni plugin version"
|
|
ansible.builtin.command: "cat {{ hashi_nomad_cni_plugins_install_path }}/version"
|
|
changed_when: false
|
|
check_mode: false
|
|
register: _cni_plugins_old_release
|
|
when: _cni_plugins_is_installed.stat.exists
|
|
|
|
- name: "Set facts for wanted cni plugins release"
|
|
ansible.builtin.set_fact:
|
|
hashi_nomad_cni_plugins_wanted_version: "{{ _cni_plugins_new_release.json['tag_name']|regex_replace('v', '') }}"
|
|
when: _cni_plugins_new_release.json is defined
|
|
and (_cni_plugins_new_release.json | length > 0)
|
|
|
|
- name: "Set facts for current cni plugins release"
|
|
ansible.builtin.set_fact:
|
|
hashi_nomad_cni_plugins_current_version: "{{ _cni_plugins_old_release.stdout | regex_replace('v', '') }}"
|
|
when: _cni_plugins_old_release.stdout is defined
|
|
and (_cni_plugins_old_release.stdout | length > 0)
|
|
|
|
- name: "Create cni directory"
|
|
ansible.builtin.file:
|
|
path: "{{ hashi_nomad_cni_plugins_install_path }}"
|
|
state: directory
|
|
mode: "0775"
|
|
|
|
- name: "Install cni plugins"
|
|
when: hashi_nomad_cni_plugins_current_version is not defined
|
|
or hashi_nomad_cni_plugins_wanted_version not in hashi_nomad_cni_plugins_current_version
|
|
block:
|
|
- name: "Install cni plugins version:{{ hashi_nomad_cni_plugins_version }}"
|
|
ansible.builtin.get_url:
|
|
url: "{{ hashi_nomad_cni_plugins_github_url }}/releases/download/v{{ hashi_nomad_cni_plugins_wanted_version }}/cni-plugins-linux-{{ hashi_nomad_cni_plugins_arch }}-v{{ hashi_nomad_cni_plugins_wanted_version }}.tgz"
|
|
dest: "/tmp/cni_plugin.tgz"
|
|
mode: "0644"
|
|
register: _cni_plugins_download_archive
|
|
until: _cni_plugins_download_archive is succeeded
|
|
retries: 5
|
|
delay: 2
|
|
check_mode: false
|
|
|
|
- name: "Unpack cni plugins"
|
|
ansible.builtin.unarchive:
|
|
src: "/tmp/cni_plugin.tgz"
|
|
dest: "{{ hashi_nomad_cni_plugins_install_path }}"
|
|
remote_src: true
|
|
|
|
- name: "Remove temporary archive"
|
|
ansible.builtin.file:
|
|
path: "/tmp/cni_plugin.tgz"
|
|
state: absent
|
|
|
|
- name: "Update version file"
|
|
ansible.builtin.copy:
|
|
content: "{{ hashi_nomad_cni_plugins_wanted_version }}"
|
|
dest: "{{ hashi_nomad_cni_plugins_install_path }}/version"
|
|
mode: "0600"
|