mirror of
https://git.lapiole.org/dani/ansible-roles.git
synced 2025-07-27 00:05:44 +02:00
Update to 2022-09-02 18:00
This commit is contained in:
11
roles/consul_template/defaults/main.yml
Normal file
11
roles/consul_template/defaults/main.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
|
||||
# Version of consul-template to install
|
||||
consul_tpl_version: 0.29.2
|
||||
# URL of the archive
|
||||
consul_tpl_archive_url: https://releases.hashicorp.com/consul-template/{{ consul_tpl_version }}/consul-template_{{ consul_tpl_version }}_linux_amd64.zip
|
||||
# Expected sha256 of the archive
|
||||
consul_tpl_archive_sha256: 88d57a227967da2f7c14f702245adcf30d80ec59354ed43c8778eb7296c9d4db
|
||||
|
||||
# Root dir where consul-template will be installed
|
||||
consul_tpl_root_dir: /opt/consul_template
|
14
roles/consul_template/tasks/archive_post.yml
Normal file
14
roles/consul_template/tasks/archive_post.yml
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
|
||||
- name: Compress previous version
|
||||
command: tar cf {{ consul_tpl_root_dir }}/archives/{{ consul_tpl_current_version }}.tar.zst --use-compress-program=zstd ./
|
||||
args:
|
||||
chdir: "{{ consul_tpl_root_dir }}/archives/{{ consul_tpl_current_version }}"
|
||||
warn: False
|
||||
environment:
|
||||
ZSTD_CLEVEL: 10
|
||||
tags: consul,vault
|
||||
|
||||
- name: Remove archive dir
|
||||
file: path={{ consul_tpl_root_dir }}/archives/{{ consul_tpl_current_version }} state=absent
|
||||
tags: consul,vault
|
16
roles/consul_template/tasks/archive_pre.yml
Normal file
16
roles/consul_template/tasks/archive_pre.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
|
||||
- name: Create the archive dir
|
||||
file: path={{ consul_tpl_root_dir }}/archives/{{ consul_tpl_current_version }} state=directory
|
||||
tags: consul,vault
|
||||
|
||||
- name: Backup previous version
|
||||
synchronize:
|
||||
src: "{{ consul_tpl_root_dir }}/{{ item }}"
|
||||
dest: "{{ consul_tpl_root_dir }}/archives/{{ consul_tpl_current_version }}/"
|
||||
compress: False
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
loop:
|
||||
- bin
|
||||
tags: consul,vault
|
||||
|
13
roles/consul_template/tasks/directories.yml
Normal file
13
roles/consul_template/tasks/directories.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
---
|
||||
|
||||
- name: Create directories
|
||||
file: path={{ consul_tpl_root_dir }}/{{ item.dir }} state=directory mode={{ item.mode | default(omit) }}
|
||||
loop:
|
||||
- dir: /
|
||||
- dir: bin
|
||||
- dir: archives
|
||||
mode: 700
|
||||
- dir: /tmp
|
||||
mode: 700
|
||||
- dir: /etc
|
||||
tags: consul,vault
|
36
roles/consul_template/tasks/facts.yml
Normal file
36
roles/consul_template/tasks/facts.yml
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
|
||||
# Load distribution specific variables
|
||||
- include_vars: "{{ item }}"
|
||||
with_first_found:
|
||||
- "{{ role_path }}/vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_distribution }}.yml"
|
||||
- "{{ role_path }}/vars/{{ ansible_os_family }}.yml"
|
||||
tags: consul,vault
|
||||
|
||||
- set_fact: consul_tpl_install_mode='none'
|
||||
tags: consul,vault
|
||||
|
||||
- name: Detect if consul_tpl is installed
|
||||
stat: path=/usr/local/bin/consul_tpl
|
||||
register: consul_tpl_bin
|
||||
tags: consul,vault
|
||||
|
||||
- when: not consul_tpl_bin.stat.exists
|
||||
set_fact: consul_tpl_install_mode='install'
|
||||
tags: consul,vault
|
||||
|
||||
- when: consul_tpl_bin.stat.exists
|
||||
block:
|
||||
- name: Detect installed version
|
||||
shell: /usr/local/bin/consul-template -version | perl -pe 's/consul\-template v(\d+(\.\d+)*).*/$1/'
|
||||
changed_when: False
|
||||
register: consul_tpl_current_version
|
||||
- set_fact: consul_tpl_current_version={{ consul_tpl_current_version.stdout }}
|
||||
tags: consul,vault
|
||||
|
||||
- when: consul_tpl_bin.stat.exists and consul_tpl_current_version != consul_tpl_version
|
||||
set_fact: consul_tpl_install_mode='upgrade'
|
||||
tags: consul,vault
|
||||
|
32
roles/consul_template/tasks/install.yml
Normal file
32
roles/consul_template/tasks/install.yml
Normal file
@@ -0,0 +1,32 @@
|
||||
---
|
||||
|
||||
- name: Install needed tools
|
||||
package: name={{ consul_tpl_packages }}
|
||||
tags: consul,vault
|
||||
|
||||
- when: consul_tpl_install_mode != 'none'
|
||||
block:
|
||||
- name: Download consul_tpl
|
||||
get_url:
|
||||
url: "{{ consul_tpl_archive_url }}"
|
||||
dest: "{{ consul_tpl_root_dir }}/tmp"
|
||||
checksum: sha256:{{ consul_tpl_archive_sha256 }}
|
||||
mode: 755
|
||||
|
||||
- name: Extract the archive
|
||||
unarchive:
|
||||
src: "{{ consul_tpl_root_dir }}/tmp/consul-template_{{ consul_tpl_version }}_linux_amd64.zip"
|
||||
dest: "{{ consul_tpl_root_dir }}/tmp"
|
||||
remote_src: True
|
||||
|
||||
- name: Install consul_tpl binary
|
||||
copy:
|
||||
src: "{{ consul_tpl_root_dir }}/tmp/consul-template"
|
||||
dest: "{{ consul_tpl_root_dir }}/bin/consul-template"
|
||||
remote_src: True
|
||||
mode: 755
|
||||
|
||||
- name: Link in /usr/local/bin
|
||||
file: src={{ consul_tpl_root_dir }}/bin/consul-template dest=/usr/local/bin/consul-template state=link force=True
|
||||
tags: consul,vault
|
||||
|
18
roles/consul_template/tasks/main.yml
Normal file
18
roles/consul_template/tasks/main.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
|
||||
- include_tasks: directories.yml
|
||||
tags: always
|
||||
|
||||
- include_tasks: facts.yml
|
||||
tags: always
|
||||
|
||||
- include_tasks: archive_pre.yml
|
||||
when: consul_tpl_install_mode | default('none') == 'upgrade'
|
||||
tags: always
|
||||
|
||||
- include_tasks: install.yml
|
||||
tags: always
|
||||
|
||||
- include_tasks: archive_post.yml
|
||||
when: consul_tpl_install_mode | default('none') == 'upgrade'
|
||||
tags: always
|
4
roles/consul_template/vars/RedHat-8.yml
Normal file
4
roles/consul_template/vars/RedHat-8.yml
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
|
||||
consul_tpl_packages:
|
||||
- zip
|
Reference in New Issue
Block a user