build role
This commit is contained in:
parent
87f2a6b138
commit
a8055a8ae7
@ -1,2 +1,26 @@
|
||||
---
|
||||
# defaults file for ansible-consul
|
||||
consul_server: True
|
||||
consul_ui: True
|
||||
consul_iface: "{{ ansible_default_ipv4.interface }}"
|
||||
consul_bind_address: "{{ hostvars[inventory_hostname]['ansible_'+ consul_iface | replace('-', '_')]['ipv4']['address']}}"
|
||||
consul_client_addr: ""
|
||||
consul_bootstrap: False
|
||||
|
||||
consul_data_dir: "/opt/consul"
|
||||
consul_datacenter: "dc1"
|
||||
consul_gossip_encryption_key:
|
||||
|
||||
consul_ansible_group: "consul"
|
||||
consul_servers_list: "\
|
||||
{% set _consul_servers_list = [] %}\
|
||||
{% for host in groups[consul_ansible_group] %}\
|
||||
{% set _consul_server = hostvars[host]['consul_server']|default(true,true) %}\
|
||||
{% if ( _consul_server == True) %}\
|
||||
{% if _consul_servers_list.append(host) %}{% endif %}\
|
||||
{% endif %}\
|
||||
{% endfor %}\
|
||||
{{ _consul_servers_list }}"
|
||||
|
||||
consul_join: []
|
||||
consul_join_wan: []
|
||||
|
@ -1,2 +1,27 @@
|
||||
---
|
||||
# tasks file for ansible-consul
|
||||
- name: Include OS-specific variables
|
||||
include_vars: "{{ item }}"
|
||||
with_first_found:
|
||||
- files:
|
||||
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
|
||||
- "{{ ansible_os_family }}.yml"
|
||||
|
||||
- name: install package
|
||||
package:
|
||||
name: "{{ consul_os_package }}"
|
||||
state: present
|
||||
|
||||
- name: apply config template
|
||||
block:
|
||||
- name: server template
|
||||
template:
|
||||
src: config.hcl.j2
|
||||
dest: /etc/consul.d/config.hcl
|
||||
owner: consul
|
||||
mode: 644
|
||||
|
||||
- name: ensure service is started
|
||||
systemd:
|
||||
name: "{{ consul_service_name }}"
|
||||
state: started
|
||||
enabled: True
|
||||
|
41
templates/config.hcl.j2
Normal file
41
templates/config.hcl.j2
Normal file
@ -0,0 +1,41 @@
|
||||
|
||||
bootstrap= {{consul_bootstrap|lower}}
|
||||
server= {{consul_server|lower}}
|
||||
|
||||
{% if consul_bind_address %}
|
||||
bind_addr="{{consul_bind_address}}"
|
||||
{% endif %}
|
||||
{% if consul_client_addr %}
|
||||
client_addr="{{consul_client_addr}}"
|
||||
{% endif %}
|
||||
|
||||
{%if consul_ui %}
|
||||
ui_config {
|
||||
enabled = true
|
||||
}
|
||||
{%endif%}
|
||||
|
||||
{% if consul_gossip_encryption_key %}
|
||||
encrypt= "{{consul_gossip_encryption_key}}"
|
||||
{% endif %}
|
||||
|
||||
|
||||
datacenter= "{{consul_datacenter}}"
|
||||
data_dir= "{{consul_data_dir}}"
|
||||
acl {
|
||||
enabled = false
|
||||
default_policy = "allow"
|
||||
enable_token_persistence = true
|
||||
}
|
||||
|
||||
{% for server in _consul_lan_servers %}
|
||||
{% set _ = consul_join.append(hostvars[server]['consul_bind_address'] | default(hostvars[server]['ansible_default_ipv4']['address'],true) | mandatory) %}
|
||||
{% endfor %}
|
||||
retry_join= {{ consul_join | map('ipwrap') | list | to_json }}
|
||||
|
||||
{% if _consul_wan_servercount | int > 0 %}
|
||||
{% for server in _consul_wan_servers %}
|
||||
{% set _ = consul_join_wan.append(hostvars[server]['consul_bind_address']) %}
|
||||
{% endfor %}
|
||||
retry_join_wan= {{ consul_join_wan | map('ipwrap') | list | to_json }}
|
||||
{% endif %}
|
6
vars/Archlinux.yml
Normal file
6
vars/Archlinux.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
consul_os_package:
|
||||
- consul
|
||||
- consul-template
|
||||
|
||||
consul_service_name: consul
|
@ -1,2 +1,23 @@
|
||||
---
|
||||
# vars file for ansible-consul
|
||||
_consul_lan_servers: "\
|
||||
{% set __consul_lan_servers = [] %}\
|
||||
{% for server in consul_servers_list %}\
|
||||
{% set _consul_datacenter = hostvars[server]['consul_datacenter'] | default('dc1', true) %}\
|
||||
{% if _consul_datacenter == consul_datacenter %}\
|
||||
{% if __consul_lan_servers.append(server) %}{% endif %}\
|
||||
{% endif %}\
|
||||
{% endfor %}\
|
||||
{{ __consul_lan_servers }}"
|
||||
_consul_lan_servercount: "{{ (_consul_lan_servers | length) }}"
|
||||
|
||||
_consul_wan_servers: "\
|
||||
{% set __consul_wan_servers = [] %}\
|
||||
{% for server in consul_servers_list %}\
|
||||
{% set _consul_datacenter = hostvars[server]['consul_datacenter'] | default('dc1', true) %}\
|
||||
{% if _consul_datacenter != consul_datacenter %}\
|
||||
{% if __consul_wan_servers.append(server) %}{% endif %}\
|
||||
{% endif %}\
|
||||
{% endfor %}\
|
||||
{{ __consul_wan_servers }}"
|
||||
_consul_wan_servercount: "{{ (_consul_wan_servers | length) }}"
|
||||
|
Loading…
Reference in New Issue
Block a user