forked from ajacocks/terraform-rpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.yml
90 lines (89 loc) · 3.27 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
- name: Automatically generate RPMs from Terraform downloads
hosts: localhost
vars:
- arch: "amd64"
- version: "current"
- downloadURL: "https://releases.hashicorp.com/terraform/"
- releaseURL: "https://github.com/hashicorp/terraform/releases/latest"
- rpmTools:
- rpm-build
- rpmdevtools
tasks:
- name: install required rpm development tools
package:
name: "{{ item }}"
state: latest
with_items: "{{ rpmTools }}"
become: yes
- name: create rpm development tree in user home directory
command: rpmdev-setuptree
- name: create temp working directory
tempfile:
state: directory
prefix: "tf."
register: tempdir
- name: get the latest release file from github
get_url:
url: "{{ releaseURL }}"
dest: "{{ tempdir.path }}/latest"
- name: register the contents
slurp:
src: "{{ tempdir.path }}/latest"
register: releaseFile
- name: set the release variable
set_fact:
version: "{{ releaseFile.content | b64decode | regex_search('<title>.*</title>') | regex_replace('^<title>Release v','') | regex_replace(' .*$','') }}"
when: version == "current"
- debug:
var: version
- name: get the latest release archive from hashicorp
get_url:
url: "{{ downloadURL }}{{ version }}/terraform_{{ version }}_linux_{{ arch }}.zip"
dest: "{{ tempdir.path }}/terraform_{{ version }}_linux_{{ arch }}.zip"
- name: create source archive build directory
file:
path: "{{ tempdir.path }}/terraform-{{ version }}"
state: directory
- name: extract terraform zipfile to build directory
unarchive:
src: "{{ tempdir.path }}/terraform_{{ version }}_linux_{{ arch }}.zip"
dest: "{{ tempdir.path }}/terraform-{{ version }}/"
- name: get the docs from github
get_url:
url: "{{ item.src }}"
dest: "{{ tempdir.path }}/terraform-{{ version }}/{{ item.name }}"
with_items:
- { name: "BUILDING.md", src: "https://github.com/hashicorp/terraform/raw/master/BUILDING.md" }
- { name: "CHANGELOG.md", src: "https://github.com/hashicorp/terraform/raw/master/CHANGELOG.md" }
- { name: "LICENSE", src: "https://github.com/hashicorp/terraform/raw/master/LICENSE" }
- { name: "README.md", src: "https://github.com/hashicorp/terraform/raw/master/README.md" }
- name: create the new source archive
archive:
path: "{{ tempdir.path }}/terraform-{{ version }}"
dest: "{{ ansible_env.HOME }}/rpmbuild/SOURCES/terraform-{{ version }}.tar"
format: tar
- name: remove temp directory
file:
path: "{{ tempdir.path }}"
state: absent
- name: remove existing spec files
file:
path: "{{ ansible_env.HOME }}/rpmbuild/SPECS/terraform-{{ version }}.spec"
state: absent
- name: create spec file from template
template:
src: terraform.spec.j2
dest: "{{ ansible_env.HOME }}/rpmbuild/SPECS/terraform-{{ version }}.spec"
- name: build rpm
command: "rpmbuild -bb {{ ansible_env.HOME }}/rpmbuild/SPECS/terraform-{{ version }}.spec"
register: rpmbuild
- name: set the rpm file variable
set_fact:
rpmFile: "{{ rpmbuild.stdout_lines.8 | regex_replace('^Wrote: ','') }}"
- debug:
var: rpmFile
- name: install terraform
package:
name: "{{ rpmFile }}"
state: latest
become: true