Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop redownloading cni #200

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,5 @@ nomad_cni_version: "{{ lookup('env', 'NOMAD_CNI_VERSION') | default('0.9.1', tru
nomad_cni_pkg: cni-plugins-linux-{{ nomad_architecture }}-v{{ nomad_cni_version }}.tgz
nomad_cni_url: https://github.com/containernetworking/plugins/releases/download/v{{ nomad_cni_version }}
nomad_cni_zip_url: "{{ nomad_cni_url }}/{{ nomad_cni_pkg }}"
nomad_cni_checksum_file: "{{ nomad_cni_pkg }}.sha256"
nomad_cni_checksum_file_url: "{{ nomad_cni_zip_url }}.sha256"
43 changes: 37 additions & 6 deletions tasks/cni.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,59 @@

- name: Check CNI package checksum file
ansible.builtin.stat:
path: "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS"
path: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
become: false
run_once: true
tags: installation
register: nomad_cni_checksum
delegate_to: 127.0.0.1

- name: Get Nomad CNI package checksum file
ansible.builtin.get_url:
url: "{{ nomad_cni_checksum_file_url }}"
dest: "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS"
dest: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
mode: "0640"
become: false
run_once: true
tags: installation
when: not nomad_cni_checksum.stat.exists
delegate_to: 127.0.0.1

- name: Re-check CNI package checksum file
ansible.builtin.stat:
path: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
become: false
tags: installation
register: nomad_cni_checksum
delegate_to: 127.0.0.1

- name: Read previously installed checksum
ansible.builtin.stat:
path: "{{ nomad_cni_dir }}/{{ nomad_cni_checksum_file }}"
tags: installation
register: nomad_cni_remote_checksum

- name: Check if new CNI should be installed
ansible.builtin.set_fact:
nomad_should_install_cni: "{{ not nomad_cni_remote_checksum.stat.exists or nomad_cni_remote_checksum.stat.checksum != nomad_cni_checksum.stat.checksum }}"

- name: Get Nomad CNI package checksum # noqa no-changed-when
ansible.builtin.shell: |
set -o pipefail
grep "{{ nomad_cni_pkg }}" "{{ role_path }}/files/nomad_cni_{{ nomad_cni_version }}_SHA256SUMS" | awk '{print $1}'
grep "{{ nomad_cni_pkg }}" "{{ role_path }}/files/{{ nomad_cni_checksum_file }}" | awk '{print $1}'
args:
executable: /bin/bash
become: false
register: nomad_cni_sha256
tags: installation
delegate_to: 127.0.0.1
when: nomad_should_install_cni

- name: Check Nomad CNI package file
ansible.builtin.stat:
path: "{{ role_path }}/files/{{ nomad_cni_pkg }}"
become: false
register: nomad_cni_package
delegate_to: 127.0.0.1
when: nomad_should_install_cni

- name: Download Nomad CNI
ansible.builtin.get_url:
Expand All @@ -57,7 +75,9 @@
become: false
tags: installation
delegate_to: 127.0.0.1
when: not nomad_cni_package.stat.exists
when:
- nomad_should_install_cni
- not nomad_cni_package.stat.exists

- name: Create Temporary Directory for Extraction
ansible.builtin.tempfile:
Expand All @@ -67,6 +87,7 @@
register: install_temp
tags: installation
delegate_to: 127.0.0.1
when: nomad_should_install_cni

- name: Unarchive Nomad CNI
ansible.builtin.unarchive:
Expand All @@ -76,6 +97,7 @@
become: false
tags: installation
delegate_to: 127.0.0.1
when: nomad_should_install_cni

- name: Install Nomad CNI
ansible.builtin.copy:
Expand All @@ -88,6 +110,14 @@
- "{{ install_temp.path }}/*"
tags: installation
notify: Restart nomad
when: nomad_should_install_cni

- name: Save install checksum record
copy:
src: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
dest: "{{ nomad_cni_dir }}"
tags: installation
when: nomad_should_install_cni

- name: Cleanup
ansible.builtin.file:
Expand All @@ -96,3 +126,4 @@
become: false
tags: installation
delegate_to: 127.0.0.1
when: nomad_should_install_cni
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
notify:
- Restart nomad

- name: Remove custome configuration
- name: Remove custom configuration
ansible.builtin.file:
dest: "{{ nomad_config_dir }}/custom.json"
state: absent
Expand Down