Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for latest version and UI IP address setting #211

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ An instance might be defined through:
```yml
# enable ui
consul_is_ui: true
# set ui listen ip
consul_ui_server_ip: 0.0.0.0 (127.0.0.1 if not defined)
# start as a server
consul_is_server: true
# name datacenter
Expand Down
4 changes: 0 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
---
consul_version: 0.6.3
consul_archive: "consul_{{ consul_version }}_linux_amd64.zip"
consul_download: "https://releases.hashicorp.com/consul/{{ consul_version }}/{{ consul_archive }}"
consul_download_username: ""
consul_download_password: ""
consul_download_folder: /tmp

consul_is_ui: false
consul_ui_archive: "consul_{{ consul_version }}_web_ui.zip"
consul_ui_download: "https://releases.hashicorp.com/consul/{{ consul_version }}/{{ consul_ui_archive }}"
consul_ui_dir: "{{ consul_home }}/dist"
consul_ui_server_name: "{{ ansible_fqdn }}"
consul_ui_require_auth: false
Expand Down
20 changes: 20 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
---
- name: get download page
uri:
url: "https://www.consul.io/downloads.html"
method: GET
return_content: yes
register: download_html
when: consul_version == 'latest'

- set_fact: consul_download_version="{{ download_html|replace('\n','')|regex_replace('.*(https://github\.com/hashicorp/consul/blob/v([0-9,.]+)/CHANGELOG\.md).*', '\2') }}"
when: consul_version == 'latest'

- set_fact: consul_download_version="{{ consul_version }}"
when: consul_version != 'latest'

- set_fact:
consul_archive: "consul_{{ consul_download_version }}_linux_amd64.zip"
consul_download: "https://releases.hashicorp.com/consul/{{ consul_download_version }}/consul_{{ consul_download_version }}_linux_amd64.zip"
consul_ui_archive: "consul_{{ consul_download_version }}_web_ui.zip"
consul_ui_download: "https://releases.hashicorp.com/consul/{{ consul_download_version }}/consul_{{ consul_download_version }}_web_ui.zip"

- name: update apt
apt: >
update_cache=yes
Expand Down
24 changes: 15 additions & 9 deletions templates/consul.json.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
{% if consul_is_ui == true %}
{% if consul_version | version_compare('0.6.1', '<') %}
"ui_dir": "{{ consul_ui_dir }}",
{% else %}
"ui": true,
{% endif %}
{% if consul_version | version_compare('0.6.1', '<') %}
"ui_dir": "{{ consul_ui_dir }}",
{% else %}
"ui": true,
{% endif %}
{% endif %}
{% if consul_join_at_start is defined and consul_join_at_start %}
"start_join": [{% for host in consul_servers | difference(ansible_all_ipv4_addresses) %}"{{host}}"{% if not loop.last %}, {% endif %}{% endfor %}],
Expand Down Expand Up @@ -36,9 +36,9 @@
"*": "{{ consul_dns_service_ttl }}"
},
"enable_truncate": {{ "true" if consul_dns_enable_truncate else "false" }},
{%- if (consul_udp_answer_limit is defined) %}
{% if (consul_udp_answer_limit is defined) -%}
"udp_answer_limit": {{ consul_udp_answer_limit }},
{%- endif %}
{% endif -%}
"only_passing": {{ "true" if consul_dns_only_passing else "false" }}
},
{% endif %}
Expand Down Expand Up @@ -102,7 +102,9 @@
"dns": {{ consul_port_dns }},
"http": {{ consul_port_http }},
"https": {{ consul_port_https }},
{% if consul_download_version|version_compare('1.0.0', '<') %}
"rpc": {{ consul_port_rpc }},
{% endif %}
"serf_lan": {{ consul_port_serf_lan }},
"serf_wan": {{ consul_port_serf_wan }},
"server": {{ consul_port_server }}
Expand Down Expand Up @@ -149,7 +151,7 @@
"disable_hostname": {{ "true" if consul_telemetry_disable_hostname else "false" }}
},
{% endif %}
{% if consul_cors_support is defined %}
{% if consul_cors_support is defined and consul_download_version|version_compare('1.0.0', '<') %}
"http_api_response_headers": {
"Access-Control-Allow-Origin": "*"
},
Expand All @@ -159,6 +161,10 @@
{% endif %}
"rejoin_after_leave": {{ "true" if consul_rejoin_after_leave else "false" }},
"leave_on_terminate": {{ "true" if consul_leave_on_terminate else "false" }},
{% if consul_ui_server_ip is defined %}
"addresses": {
"http": "{{ consul_ui_server_ip }}"
},
{% endif %}
"disable_update_check": {{ "true" if consul_disable_update_check else "false" }}

}