Manage terraform binary

This commit is contained in:
2021-10-02 11:09:14 +02:00
parent 2cbe7dde04
commit 138a1d2f32

View File

@@ -257,8 +257,6 @@
owner: "{{ user.name }}"
group: "{{ user_group_name }}"
with_items:
- name: terraform
optpath: terraform
- name: hugo
optpath: hugo
- name: drone
@@ -460,6 +458,70 @@
tags:
- kubectl
- block:
- name: set terraform version
set_fact:
terraform_version: 1.0.2
- name: stat current terraform binary
stat:
path: "/home/{{ user.name }}/.opt/terraform-v{{ terraform_version }}"
register: terraform_binary
- name: create temporary download directory for terraform
tempfile:
state: directory
register: terraform_download_dir
when: not terraform_binary.stat.exists
- name: get terraform
get_url:
url: "https://releases.hashicorp.com/terraform/{{ terraform_version }}/terraform_{{ terraform_version }}_linux_amd64.zip"
dest: "{{ terraform_download_dir.path }}/terraform.zip"
when: not terraform_binary.stat.exists
- name: unpack terraform zip
unarchive:
src: "{{ terraform_download_dir.path }}/terraform.zip"
dest: "{{ terraform_download_dir.path }}/"
remote_src: true
when: not terraform_binary.stat.exists
- name: install terraform
command: mv "{{ terraform_download_dir.path }}/terraform" /home/{{ user.name }}/.opt/terraform-v{{ terraform_version }}
when: not terraform_binary.stat.exists
- name: clean up download directory
file:
path: "{{ terraform_download_dir.path }}"
state: absent
when: not terraform_binary.stat.exists
- name: link terraform
file:
src: /home/{{ user.name }}/.opt/terraform-v{{ terraform_version }}
dest: /home/{{ user.name }}/.optbin/terraform
state: link
- name: get terraform version info
command: /home/{{ user.name }}/.optbin/terraform version -json
register: terraform_version_output
changed_when: false
- name: parse terraform version output
set_fact:
terraform_outdated: "{{ (terraform_version_output.stdout | from_json()).terraform_outdated }}"
changed_when: false
- name: warn if terraform is outdated
fail:
msg: "current terraform v{{ terraform_version }} is out of date"
when: terraform_outdated is sameas true
ignore_errors: True
tags:
- terraform
- name: handle autostart units
block:
- name: create systemd user directory