Skip to content

Commit

Permalink
Link approach (#30)
Browse files Browse the repository at this point in the history
* Link approach

* Fix consul-template
  • Loading branch information
ahelal authored Aug 16, 2017
1 parent 5fac770 commit 460a32a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 31 deletions.
51 changes: 36 additions & 15 deletions tasks/install/consul-agent.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
---

- name: install | consul agent | Check agent archive stat
- name: install | consul agent | Check target file
stat:
path="{{ consul_tmp_dir }}/{{ consul_agent_archive }}"
register: consul_agent_archive_stat
path="{{ consul_bin_dir }}/consul"
register: consul_agent_target_link

- name: install | consul agent | Download consul agent (if needed)
get_url:
url="{{ consul_agent_download_url }}"
dest="{{ consul_tmp_dir }}"
owner="{{ consul_user }}"
register: consul_agent_get
when: consul_agent_archive_stat.stat.exists == False
- name: install | consul agent | Remove target file (if not symlink)
file:
path="{{ consul_bin_dir }}/consul"
state="absent"
when: not consul_agent_target_link.stat.islnk is defined or not consul_agent_target_link.stat.islnk

- name: install | consul agent | Check agent binary
stat:
path="{{ consul_bin_dir }}/consul-{{consul_agent_version}}"
register: consul_agent_version_binary

- name: install | consul agent | Ensure download directory exists
file:
path="{{ consul_tmp_dir }}/consul-{{ consul_agent_version }}"
state=directory
mode=0755

- name: install | consul agent | Unpack consul arcive (if needed)
- name: install | consul agent | Download and unpack consul archive (if needed)
unarchive:
src="{{ consul_tmp_dir }}/{{ consul_agent_archive }}"
dest="{{ consul_bin_dir }}"
copy="no"
src="{{ consul_agent_download_url }}"
dest="{{ consul_tmp_dir }}/consul-{{ consul_agent_version }}/"
copy=false
owner="{{ consul_user }}"
when: consul_agent_get | changed
when: not consul_agent_version_binary.stat.exists

- name: install | consul agent | link binary (if needed)
command: mv {{ consul_tmp_dir }}/consul-{{ consul_agent_version }}/consul {{ consul_bin_dir }}/consul-{{consul_agent_version}}
when: not consul_agent_version_binary.stat.exists
notify:
- restart consul service

- name: install | consul agent | Consul link binary
file:
src="{{ consul_bin_dir }}/consul-{{consul_agent_version}}"
dest="{{ consul_bin_dir }}/consul"
state="link"
notify:
- restart consul service

Expand Down
53 changes: 37 additions & 16 deletions tasks/install/consul-template.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
---

- name: install | consul template install | Check tempalate archive stat
- name: install | consul template | Check target file
stat:
path="{{ consul_tmp_dir }}/{{ consul_template_archive }}"
register: consul_template_archive_stat
path="{{ consul_bin_dir }}/consul-template"
register: consul_template_target_link

- name: install | consul template | Download consul template (if needed)
get_url:
url="{{ consul_template_download_url }}"
dest="{{ consul_tmp_dir }}"
owner="{{ consul_user }}"
register: consul_template_get
when: consul_template_archive_stat.stat.exists == False
- name: install | consul template | Remove target file (if not symlink)
file:
path="{{ consul_bin_dir }}/consul-template"
state="absent"
when: not consul_template_target_link.stat.islnk is defined or not consul_template_target_link.stat.islnk

- name: install | consul template | Check template binary
stat:
path="{{ consul_tmp_dir }}/consul-template-{{ consul_template_version }}"
register: consul_template_version_binary

- name: install | consul template | Ensure download directory exists
file:
path="{{ consul_tmp_dir }}/consul-template-{{ consul_template_version }}"
state=directory
mode=0755

- name: install | consul template | Unpack consul arcive (if needed)
- name: install | consul template | Download and unpack consul--template archive (if needed)
unarchive:
src="{{ consul_tmp_dir }}/{{ consul_template_archive }}"
dest="{{ consul_bin_dir }}"
copy="no"
src="{{ consul_template_download_url }}"
dest="{{ consul_tmp_dir }}/consul-template-{{ consul_template_version }}"
copy=false
owner="{{ consul_user }}"
when: consul_template_get | changed
when: not consul_template_version_binary.stat.exists

- name: install | consul template | link binary (if needed)
command: mv {{ consul_tmp_dir }}/consul-template-{{ consul_template_version }}/consul-template {{ consul_bin_dir }}/consul-template-{{consul_template_version}}
when: not consul_template_version_binary.stat.exists
notify:
- restart consul service

- name: install | consul template | Consul template link binary
file:
src="{{ consul_bin_dir }}/consul-template-{{ consul_template_version }}"
dest="{{ consul_bin_dir }}/consul-template"
state="link"
notify:
- restart consul service

Expand Down Expand Up @@ -102,7 +123,7 @@
- restart consul-template service
- reload haproxy service

- name: install | consul template | Ensure HAproxy reload script is deployed
- name: install | consul template | Ensure HAProxy reload script is deployed
template:
src="haproxy-reload.j2"
dest="{{ consul_bin_dir }}/haproxy-reload"
Expand Down

0 comments on commit 460a32a

Please sign in to comment.