Skip to content

Commit 7179d7e

Browse files
committed
Improve install speed by not installing if the same file was previously installed
This is done by storing the checksum used on the server after installation. This checksum file is then compared to the local checksum file for the requested CNI plugins. If they do not match (hash has changed or version is different), then plugins will be installed or updated.
1 parent 00a8e8c commit 7179d7e

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

tasks/cni.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727
when: not nomad_cni_checksum.stat.exists
2828
delegate_to: 127.0.0.1
2929

30+
- name: Re-check CNI package checksum file
31+
ansible.builtin.stat:
32+
path: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
33+
become: false
34+
tags: installation
35+
register: nomad_cni_checksum
36+
delegate_to: 127.0.0.1
37+
38+
- name: Read previously installed checksum
39+
ansible.builtin.stat:
40+
path: "{{ nomad_cni_dir }}/{{ nomad_cni_checksum_file }}"
41+
tags: installation
42+
register: nomad_cni_remote_checksum
43+
44+
- name: Check if new CNI should be installed
45+
ansible.builtin.set_fact:
46+
nomad_should_install_cni: "{{ not nomad_cni_remote_checksum.stat.exists or nomad_cni_remote_checksum.stat.checksum != nomad_cni_checksum.stat.checksum }}"
47+
3048
- name: Get Nomad CNI package checksum # noqa no-changed-when
3149
ansible.builtin.shell: |
3250
set -o pipefail
@@ -37,13 +55,15 @@
3755
register: nomad_cni_sha256
3856
tags: installation
3957
delegate_to: 127.0.0.1
58+
when: nomad_should_install_cni
4059

4160
- name: Check Nomad CNI package file
4261
ansible.builtin.stat:
4362
path: "{{ role_path }}/files/{{ nomad_cni_pkg }}"
4463
become: false
4564
register: nomad_cni_package
4665
delegate_to: 127.0.0.1
66+
when: nomad_should_install_cni
4767

4868
- name: Download Nomad CNI
4969
ansible.builtin.get_url:
@@ -55,7 +75,9 @@
5575
become: false
5676
tags: installation
5777
delegate_to: 127.0.0.1
58-
when: not nomad_cni_package.stat.exists
78+
when:
79+
- nomad_should_install_cni
80+
- not nomad_cni_package.stat.exists
5981

6082
- name: Create Temporary Directory for Extraction
6183
ansible.builtin.tempfile:
@@ -65,6 +87,7 @@
6587
register: install_temp
6688
tags: installation
6789
delegate_to: 127.0.0.1
90+
when: nomad_should_install_cni
6891

6992
- name: Unarchive Nomad CNI
7093
ansible.builtin.unarchive:
@@ -74,6 +97,7 @@
7497
become: false
7598
tags: installation
7699
delegate_to: 127.0.0.1
100+
when: nomad_should_install_cni
77101

78102
- name: Install Nomad CNI
79103
ansible.builtin.copy:
@@ -86,6 +110,14 @@
86110
- "{{ install_temp.path }}/*"
87111
tags: installation
88112
notify: Restart nomad
113+
when: nomad_should_install_cni
114+
115+
- name: Save install checksum record
116+
copy:
117+
src: "{{ role_path }}/files/{{ nomad_cni_checksum_file }}"
118+
dest: "{{ nomad_cni_dir }}"
119+
tags: installation
120+
when: nomad_should_install_cni
89121

90122
- name: Cleanup
91123
ansible.builtin.file:
@@ -94,3 +126,4 @@
94126
become: false
95127
tags: installation
96128
delegate_to: 127.0.0.1
129+
when: nomad_should_install_cni

0 commit comments

Comments
 (0)