Skip to content

Commit

Permalink
Use tempfile/win_tempfile, not hardcoded paths
Browse files Browse the repository at this point in the history
This commit also corrects some potential backslash issues on Windows.
  • Loading branch information
nre-ableton authored and bbaassssiiee committed Oct 10, 2022
1 parent c4acf70 commit e04cc02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
18 changes: 9 additions & 9 deletions tasks/install_remote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
tags: installation

- name: Validate remote Consul directory
file:
path: /tmp/consul
tempfile:
state: directory
mode: 0700
prefix: ansible-consul.
register: consul_temp_dir

- name: Read Consul package checksum file
stat:
path: "/tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
path: "{{ consul_temp_dir.path }}/consul_{{ consul_version }}_SHA256SUMS"
register: consul_checksum
changed_when: false
tags: installation

- name: Download Consul package checksum file
get_url:
url: "{{ consul_checksum_file_url }}"
dest: "/tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
dest: "{{ consul_temp_dir.path }}/consul_{{ consul_version }}_SHA256SUMS"
validate_certs: false
tags: installation
when: not consul_checksum.stat.exists | bool

- name: Read Consul package checksum
shell: "grep {{ consul_pkg }} /tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
shell: "grep {{ consul_pkg }} {{ consul_temp_dir.path }}/consul_{{ consul_version }}_SHA256SUMS"
register: consul_sha256
changed_when: false
tags:
Expand All @@ -39,7 +39,7 @@
- name: Download Consul
get_url:
url: "{{ consul_zip_url }}"
dest: "/tmp/consul/{{ consul_pkg }}"
dest: "{{ consul_temp_dir.path }}/{{ consul_pkg }}"
checksum: "sha256:{{ consul_sha256.stdout.split(' ')|first }}"
timeout: 42
register: consul_download
Expand All @@ -48,7 +48,7 @@
- name: Unarchive Consul and install binary
unarchive:
remote_src: true
src: "/tmp/consul/{{ consul_pkg }}"
src: "{{ consul_temp_dir.path }}/{{ consul_pkg }}"
dest: "{{ consul_bin_path }}"
owner: "{{ consul_user }}"
group: "{{ consul_group }}"
Expand All @@ -69,6 +69,6 @@

- name: Cleanup
file:
path: "/tmp/consul"
path: "{{ consul_temp_dir.path }}"
state: absent
tags: installation
23 changes: 12 additions & 11 deletions tasks/install_windows.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
# File: install_remote.yml - package installation tasks for Consul

- name: Validate remote Consul directory
win_file:
path: /tmp/consul
- name: Create temporary directory to download Consul
win_tempfile:
state: directory
prefix: ansible-consul.
register: consul_temp_dir

- name: Verify TLS1.2 is used
win_regedit:
Expand All @@ -15,33 +16,33 @@

- name: Read Consul package checksum file
win_stat:
path: "/tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
path: "{{ consul_temp_dir.path }}\\consul_{{ consul_version }}_SHA256SUMS"
register: consul_checksum
tags: installation

- name: Download Consul package checksum file
win_get_url:
url: "{{ consul_checksum_file_url }}"
dest: "/tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
dest: "{{ consul_temp_dir.path }}\\consul_{{ consul_version }}_SHA256SUMS"
tags: installation
when: not consul_checksum.stat.exists | bool

- name: Read Consul package checksum
win_shell: "findstr {{ consul_pkg }} /tmp/consul/consul_{{ consul_version }}_SHA256SUMS"
win_shell: "findstr {{ consul_pkg }} {{ consul_temp_dir.path }}\\consul_{{ consul_version }}_SHA256SUMS"
args:
chdir: /tmp/consul
chdir: "{{ consul_temp_dir.path }}"
register: consul_pkg_checksum
tags: installation

- name: Download Consul
win_get_url:
url: "{{ consul_zip_url }}"
dest: "/tmp/consul/{{ consul_pkg }}"
dest: "{{ consul_temp_dir.path }}\\{{ consul_pkg }}"
tags: installation

- name: Calculate checksum
win_stat:
path: "/tmp/consul/{{ consul_pkg }}"
path: "{{ consul_temp_dir.path }}\\{{ consul_pkg }}"
checksum_algorithm: sha256
register: consul_pkg_hash
tags: installation
Expand All @@ -54,12 +55,12 @@

- name: Unarchive Consul and install binary
win_unzip:
src: "/tmp/consul/{{ consul_pkg }}"
src: "{{ consul_temp_dir.path }}\\{{ consul_pkg }}"
dest: "{{ consul_bin_path }}"
tags: installation

- name: Cleanup
win_file:
path: "/tmp/consul"
path: "{{ consul_temp_dir.path }}"
state: absent
tags: installation

0 comments on commit e04cc02

Please sign in to comment.