Skip to content
This repository has been archived by the owner on Jul 30, 2023. It is now read-only.

Commit

Permalink
Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Dec 26, 2016
1 parent eeec05a commit 22de07f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 25 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ To install the role specificed in the file:
ansible-galaxy install -r requirements.yml
```

## Role Variables

Available variables are listed below, along with default values:

```yaml
# Release location base URL. Example of final URL:
# https://releases.hashicorp.com/packer/0.12.0/packer_0.12.0_linux_amd64.zip
hashicorp_releases_location: https://releases.hashicorp.com
# Where download files shall be put.
hashicorp_download_dir: /var/tmp/hashicorp
# Where HashiCorp tools shall be installed under.
hashicorp_install_dir: /opt/hashicorp
# Where symbolic links shall be added.
hashicorp_system_bin_dir: /usr/local/bin
# Which system user.
hashicorp_system_user: "{{ ansible_user_id }}"
# Which system group.
hashicorp_system_group: "{{ ansible_user_id }}"
# HashiCorp tools dictionary.
hashicorp_tools_defaults:
packer:
state: absent
terraform:
state: absent
vault:
state: absent
nomad:
state: absent
consul:
state: absent
```
## Example Playbook
Example how to write to install and remove HashiCorp open source DevOps tools:
Expand Down
23 changes: 15 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
---
# defaults file

# Release location base URL. Example of final URL:
# https://releases.hashicorp.com/packer/0.12.0/packer_0.12.0_linux_amd64.zip
hashicorp_releases_location: https://releases.hashicorp.com
# Where download files shall be put.
hashicorp_download_dir: /var/tmp/hashicorp
# Where HashiCorp tools shall be installed under.
hashicorp_install_dir: /opt/hashicorp
# Where symbolic links shall be added.
hashicorp_system_bin_dir: /usr/local/bin
# Which system user.
hashicorp_system_user: "{{ ansible_user_id }}"
# Which system group.
hashicorp_system_group: "{{ ansible_user_id }}"
# HashiCorp tools dictionary.
hashicorp_tools_defaults:
packer:
state: absent
Expand All @@ -11,11 +26,3 @@ hashicorp_tools_defaults:
state: absent
consul:
state: absent
hashicorp_architecture: linux_amd64
hashicorp:
download_dir: /var/tmp/hashicorp
install_dir: /opt/hashicorp
system_bin_dir: /usr/local/bin
system_user: "{{ ansible_user_id }}"
system_group: "{{ ansible_user_id }}"
releases_location: https://releases.hashicorp.com
2 changes: 1 addition & 1 deletion tasks/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: Ensure HashiCorp temporary directory is absent
file: >
dest="{{ hashicorp.download_dir }}"
dest="{{ hashicorp_download_dir }}"
state=absent
changed_when: False

4 changes: 2 additions & 2 deletions tasks/env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

- name: Ensure HashiCorp temporary directory exists
file: >
path={{ hashicorp.download_dir }}
path={{ hashicorp_download_dir }}
state=directory
mode=0755
changed_when: False

- name: Copy helper scripts
copy:
src: ../files/fetch_hashicorp_versions.sh
dest: "{{ hashicorp.download_dir }}/fetch_hashicorp_versions.sh"
dest: "{{ hashicorp_download_dir }}/fetch_hashicorp_versions.sh"
mode: "u+rx,g+rx,o+rx"
changed_when: False
24 changes: 12 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@

- name: Ensure HashiCorp temporary directory exists
file: >
path={{ hashicorp.download_dir }}
path={{ hashicorp_download_dir }}
state=directory
mode=0755
changed_when: False

- name: Remove symbolic links to tools which have state absent
file:
path: "{{ hashicorp.system_bin_dir }}/{{ item.key }}"
path: "{{ hashicorp_system_bin_dir }}/{{ item.key }}"
state: "absent"
become: yes
when: item.value.action == "remove" or item.value.action == "replace"
with_dict: "{{hashicorp_tools_combined}}"

- name: Ensure HashiCorp tools with state absent is remove
file: >
dest="{{ hashicorp.install_dir }}/{{item.key}}/{{item.value.installed_version}}"
dest="{{ hashicorp_install_dir }}/{{item.key}}/{{item.value.installed_version}}"
state=absent
when: item.value.action == "remove" or item.value.action == "replace"
with_dict: "{{hashicorp_tools_combined}}"

- name: Downloads Packages
get_url:
url: "{{ hashicorp.releases_location }}/{{item.key}}/{{item.value.version}}/{{item.key}}_{{item.value.version}}_{{hashicorp_architecture}}.zip"
url: "{{ hashicorp_releases_location }}/{{item.key}}/{{item.value.version}}/{{item.key}}_{{item.value.version}}_{{hashicorp_architecture}}.zip"
# checksum: "{{ item.value.checksum }}"
dest: "{{ hashicorp.download_dir }}"
dest: "{{ hashicorp_download_dir }}"
mode: 0755
validate_certs: no
when: item.value.action == "install" or item.value.action == "replace"
Expand All @@ -38,7 +38,7 @@

- name: Ensure HashiCorp tool directory exists
file: >
path={{ hashicorp.install_dir }}/{{item.key}}/{{item.value.version}}/bin
path={{ hashicorp_install_dir }}/{{item.key}}/{{item.value.version}}/bin
state=directory
mode=0755
become: yes
Expand All @@ -47,21 +47,21 @@

- name: Unpack download packages
unarchive: >
src="{{ hashicorp.download_dir }}/{{item.key}}_{{item.value.version}}_{{hashicorp_architecture}}.zip"
dest="{{ hashicorp.install_dir }}/{{item.key}}/{{item.value.version}}/bin"
src="{{ hashicorp_download_dir }}/{{item.key}}_{{item.value.version}}_{{hashicorp_architecture}}.zip"
dest="{{ hashicorp_install_dir }}/{{item.key}}/{{item.value.version}}/bin"
copy=no
mode=0755
owner="{{ hashicorp.system_user }}"
group="{{ hashicorp.system_group }}"
owner="{{ hashicorp_system_user }}"
group="{{ hashicorp_system_group }}"
creates=yes
become: yes
when: item.value.action == "install" or item.value.action == "replace"
with_dict: "{{hashicorp_tools_combined}}"

- name: Creates symbolic links to Hashicorp tools
file: >
src={{ hashicorp.install_dir }}/{{item.key}}/{{item.value.version}}/bin/{{item.key}}
dest={{ hashicorp.system_bin_dir }}/{{item.key}}
src={{ hashicorp_install_dir }}/{{item.key}}/{{item.value.version}}/bin/{{item.key}}
dest={{ hashicorp_system_bin_dir }}/{{item.key}}
state=link
become: yes
when: item.value.action == "install" or item.value.action == "replace"
Expand Down
4 changes: 2 additions & 2 deletions tasks/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

- name: Find installed tools
find:
paths: "{{ hashicorp.install_dir }}/{{item.key}}"
paths: "{{ hashicorp_install_dir }}/{{item.key}}"
file_type: directory
with_dict: "{{hashicorp_tools_combined}}"
register: installed_tools
Expand All @@ -31,7 +31,7 @@
with_items: "{{installed_tools.results}}"

- name: Lookup latest released versions
command: "{{ hashicorp.download_dir }}/fetch_hashicorp_versions.sh {{item.key}}"
command: "{{ hashicorp_download_dir }}/fetch_hashicorp_versions.sh {{item.key}}"
register: fetch_versions_cmd
when: (item.value.state == "latest") or (item.value.state == "present")
with_dict: "{{hashicorp_tools_combined}}"
Expand Down

0 comments on commit 22de07f

Please sign in to comment.