hcp-ansible/roles/nomad/tasks/cni_install.yml
Bertrand Lanson 2c9f538cef
All checks were successful
development / Check commit compliance (push) Successful in 6s
feat(roles): integrate nomad role to hashistack collection
2024-07-19 23:32:24 +02:00

79 lines
3.0 KiB
YAML

---
# task/cni_install file for hashicorp_nomad
- name: "Nomad | Get release for cni_plugins:{{ nomad_cni_plugins_version }}"
vars:
_cni_plugins_url_ext: "{% if nomad_cni_plugins_version == 'latest'%}releases{% else %}releases/tags{% endif %}"
ansible.builtin.uri:
url: "{{ nomad_github_api }}/{{ nomad_cni_github_project }}/{{ _cni_plugins_url_ext }}/{{ nomad_cni_plugins_version }}"
return_content: true
register: _cni_plugins_new_release
- name: "Nomad | Check if cni plugin is already installed"
ansible.builtin.stat:
path: "{{ nomad_cni_plugins_install_path }}/version"
changed_when: false
check_mode: false
register: _cni_plugins_is_installed
- name: "Nomad | Check current cni plugin version"
ansible.builtin.command: "cat {{ 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: "Nomad | Set facts for wanted cni plugins release"
ansible.builtin.set_fact:
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: "Nomad | Set facts for current cni plugins release"
ansible.builtin.set_fact:
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: "Nomad | Create cni directory"
ansible.builtin.file:
path: "{{ nomad_cni_plugins_install_path }}"
state: directory
owner: "{{ nomad_user }}"
group: "{{ nomad_group }}"
mode: "0755"
- name: "Nomad | Install cni plugins"
when: nomad_cni_plugins_current_version is not defined
or nomad_cni_plugins_wanted_version not in nomad_cni_plugins_current_version
block:
- name: "Nomad | Install cni plugins version:{{ nomad_cni_plugins_version }}"
ansible.builtin.get_url:
url: "{{ nomad_github_url }}/{{ nomad_cni_github_project }}/releases/download/v{{ nomad_cni_plugins_wanted_version }}/cni-plugins-linux-{{ nomad_architecture }}-v{{ 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: "Nomad | Unpack cni plugins"
ansible.builtin.unarchive:
src: "/tmp/cni_plugin.tgz"
dest: "{{ nomad_cni_plugins_install_path }}"
owner: "{{ nomad_user }}"
group: "{{ nomad_group }}"
mode: "0755"
remote_src: true
- name: "Nomad | Remove temporary archive"
ansible.builtin.file:
path: "/tmp/cni_plugin.tgz"
state: absent
- name: "Nomad | Update version file"
ansible.builtin.copy:
content: "{{ nomad_cni_plugins_wanted_version }}"
dest: "{{ nomad_cni_plugins_install_path }}/version"
mode: "0600"