Skip to content

Commit

Permalink
Merge pull request #70 from groggemans/combine_config_templates
Browse files Browse the repository at this point in the history
Combine config templates
  • Loading branch information
brianshumate authored Jun 5, 2017
2 parents 9948bf6 + b6855ba commit e54d94d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 188 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ in many Ansible versions, so this feature might not always work.
- This is the only option on Windows as WinRM is somewhat limited in this scope
- Default value: *false*

### `consul_ui`

- Enable the consul ui?
- Default value: *true*

### `consul_node_role`

- Consul server role, one of: *bootstrap*, *server*, or *client*
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ consul_node_name: "{{ inventory_hostname_short }}"
consul_node_role: "{{ lookup('env','CONSUL_NODE_ROLE') | default('client', true) }}"
consul_recursors: "{{ lookup('env','CONSUL_RECURSORS') | default('[]', true) }}"
consul_bootstrap_expect: "{{ lookup('env','CONSUL_BOOTSTRAP_EXPECT') | default(false, true) }}"
consul_ui: "{{ lookup('env', 'CONSUL_UI') | default(true, true) }}"

### Addresses
consul_bind_address: "\
Expand Down
50 changes: 13 additions & 37 deletions tasks/config.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
---
# File: config.yml - Consul configuration tasks

- name: Create bootstrap configuration
template:
src: config_bootstrap.json.j2
- name: Create configuration
copy:
dest: "{{ item.dest }}"
owner: "{{ consul_user }}"
group: "{{ consul_group}}"
content: "{{ lookup('template', 'templates/config.json.j2') | to_nice_json }}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'bootstrap' }}"
config_version: "{{ consul_node_role }}"
when: true
- dest: "{{ consul_config_path }}/bootstrap.json"
when: consul_debug | bool
when:
- item.when
notify:
- restart consul

- name: Create server configuration
template:
src: config_server.json.j2
dest: "{{ item.dest }}"
owner: "{{ consul_user }}"
group: "{{ consul_group}}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'server' }}"
config_version: bootstrap
when: "{{ consul_debug | bool }}"
- dest: "{{ consul_config_path }}/server.json"
when: consul_debug | bool
when:
- item.when
notify:
- restart consul

- name: Create client configuration
template:
src: config_client.json.j2
dest: "{{ item.dest }}"
owner: "{{ consul_user }}"
group: "{{ consul_group}}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'client' }}"
config_version: server
when: "{{ consul_debug | bool }}"
- dest: "{{ consul_config_path }}/client.json"
when: consul_debug | bool
config_version: client
when: "{{ consul_debug | bool }}"
when:
- item.when
notify:
- restart consul

- name: Create custom configuration
template:
src: configd_50custom.json.j2
copy:
dest: "{{ consul_configd_path }}/50custom.json"
owner: "{{ consul_user }}"
group: "{{ consul_group}}"
content: "{{ lookup('template', 'templates/configd_50custom.json.j2') | to_nice_json }}"
when:
- consul_config_custom is defined
notify:
Expand Down
46 changes: 13 additions & 33 deletions tasks/config_windows.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,32 @@
---
# File: config.yml - Consul configuration tasks

- name: Create bootstrap configuration
win_template:
src: config_bootstrap.json.j2
- name: Create configuration
win_copy:
dest: "{{ item.dest }}"
content: "{{ lookup('template', 'templates/config.json.j2') | to_nice_json }}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'bootstrap' }}"
config_version: "{{ consul_node_role }}"
when: true
- dest: "{{ consul_config_path }}/bootstrap.json"
when: consul_debug | bool
when:
- item.when
notify:
- restart consul

- name: Create server configuration
win_template:
src: config_server.json.j2
dest: "{{ item.dest }}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'server' }}"
config_version: "bootstrap"
when: "{{ consul_debug | bool }}"
- dest: "{{ consul_config_path }}/server.json"
when: consul_debug | bool
when:
- item.when
notify:
- restart consul

- name: Create client configuration
win_template:
src: config_client.json.j2
dest: "{{ item.dest }}"
with_items:
- dest: "{{ consul_config_path }}/config.json"
when: "{{ consul_node_role == 'client' }}"
config_version: "server"
when: "{{ consul_debug | bool }}"
- dest: "{{ consul_config_path }}/client.json"
when: consul_debug | bool
config_version: "client"
when: "{{ consul_debug | bool }}"
when:
- item.when
notify:
- restart consul

- name: Create custom configuration
win_template:
src: configd_50custom.json.j2
win_copy:
dest: "{{ consul_configd_path }}/50custom.json"
content: "{{ lookup('template', 'templates/configd_50custom.json.j2') | to_nice_json }}"
when:
- consul_config_custom is defined
notify:
Expand Down
85 changes: 85 additions & 0 deletions templates/config.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{# This template will be passed through the 'to_nice_json' filter #}
{# The filter fixes whitespace, indentation and comma's on the last item #}
{
{# Common Settings #}

{## Node ##}
"node_name": "{{ consul_node_name }}",
"datacenter": "{{ consul_datacenter }}",
"domain": "{{ consul_domain }}",

{## Addresses and ports ##}
"bind_addr": "{{ consul_bind_address }}",
"addresses": {
"dns": "{{ consul_dns_bind_address }}",
"http": "{{ consul_http_bind_address }}",
"https": "{{ consul_https_bind_address }}",
"rpc": "{{ consul_rpc_bind_address }}",
},
{% if consul_ports %}
"ports": {{ consul_ports | to_json }},
{% endif %}

{## DNS ##}
{% if consul_recursors | length > 0 %}
"recursors": [
{% for recursor in consul_recursors %}
"{{ recursor }}",
{% endfor %} ],
{% endif %}

{## Agent ##}
"data_dir": "{{ consul_data_path }}",
"log_level": "{{ consul_log_level }}",
"enable_syslog": {{ consul_syslog_enable | bool | to_json }},

{# Encryption and TLS ##}
"encrypt": "{{ consul_raw_key }}",
{% if consul_tls_enable %}
"ca_file": "{{ consul_tls_dir }}/{{ consul_tls_ca_crt }}",
"cert_file": "{{ consul_tls_dir }}/{{ consul_tls_server_crt }}",
"key_file": "{{ consul_tls_dir }}/{{ consul_server_key }}",
"verify_incoming": {{ consul_tls_verify_incoming | bool | to_json }},
"verify_outgoing": {{ consul_tls_verify_outgoing | bool | to_json }},
{% endif %}

{## LAN Join ##}
"start_join": [
{% for server in _consul_lan_servers %}
"{{ hostvars[server]['consul_bind_address'] | ipwrap }}",
{% endfor %} ],

{## Server/Client ##}
"server": {{ (item.config_version != 'client') | bool | to_json }},

{## UI ##}
"ui": {{ consul_ui | bool | to_json }},

{# Server Settings #}

{% if (item.config_version == 'server') or (item.config_version == 'bootstrap') %}

{## Bootstrap settings ##}
"bootstrap": {{ (item.config_version == 'bootstrap') | bool | to_json }},
{% if consul_bootstrap_expect and not (item.config_version == 'bootstrap') %}
"bootstrap_expect": {{ _consul_lan_servers | length }},
{% endif %}

{## WAN Join ##}
{% if _consul_wan_servers | length > 0 %}
"start_join_wan": [
{% for server in _consul_wan_servers %}
"{{ hostvars[server]['consul_bind_address'] | ipwrap }}",
{% endfor %} ],
{% endif %}

{## ACL's ##}
{% if consul_acl_enable %}
"acl_datacenter": "{{ consul_acl_datacenter }}",
"acl_default_policy": "{{ consul_acl_default_policy }}",
"acl_down_policy": "{{ consul_acl_down_policy }}",
"acl_master_token": "{{ consul_acl_master_token }}",
"acl_replication_token": "{{ consul_acl_replication_token }}",
{% endif %}
{% endif %}
}
48 changes: 0 additions & 48 deletions templates/config_bootstrap.json.j2

This file was deleted.

30 changes: 0 additions & 30 deletions templates/config_client.json.j2

This file was deleted.

40 changes: 0 additions & 40 deletions templates/config_server.json.j2

This file was deleted.

0 comments on commit e54d94d

Please sign in to comment.