add consul role

This commit is contained in:
Ryan Cavicchioni 2022-08-30 07:45:41 -05:00
parent 4d07232525
commit 789541a90f
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
8 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,21 @@
---
consul_package_name: consul
consul_package_state: present
consul_service_name: consul
consul_service_state: started
consul_service_enabled: true
consul_etc_path: /etc/consul.d
consul_config_path: "{{ consul_etc_path }}/consul.hcl"
consul_config_template: consul.hcl.j2
consul_user: consul
consul_group: consul
consul_config_owner: "{{ consul_user }}"
consul_config_group: "{{ consul_group }}"
consul_config_mode: 0644
consul_data_dir: /opt/consul
consul_bind_addr: "{{ ansible_default_ipv4.address }}"
consul_server: false
consul_bootstrap_expect: 1
consul_ui_config_enabled: true
consul_client_addr: 0.0.0.0
consul_unbound_enabled: false

View File

@ -0,0 +1,9 @@
# Ansible managed
server:
do-not-query-localhost: no
domain-insecure: "consul"
stub-zone:
name: "consul"
stub-addr: 127.0.0.1@8600

View File

@ -0,0 +1,12 @@
---
- name: reload consul
service:
name: "{{ consul_service_name }}"
state: reloaded
when: consul_service_enabled
- name: restart consul
service:
name: "{{ consul_service_name }}"
state: restarted
when: consul_service_enabled

View File

@ -0,0 +1,18 @@
---
- name: install Hashicorp yum repo
yum_repository:
name: hashicorp
description: Hashicorp Stable - $basearch
baseurl: https://rpm.releases.hashicorp.com/RHEL/$releasever/$basearch/stable
enabled: 1
gpgcheck: 1
gpgkey: https://rpm.releases.hashicorp.com/gpg
- name: install Hashicorp (test) yum repo
yum_repository:
name: hashicorp-test
description: Hashicorp Test - $basearch
baseurl: https://rpm.releases.hashicorp.com/RHEL/$releasever/$basearch/test
enabled: 0
gpgcheck: 1
gpgkey: https://rpm.releases.hashicorp.com/gpg

View File

@ -0,0 +1,9 @@
---
- name: configure unbound forwarder
copy:
src: unbound-consul.conf
dest: "{{ unbound_conf_d_path }}/consul.conf"
owner: root
group: root
mode: "0644"
notify: reload unbound

View File

@ -0,0 +1,47 @@
---
- name: gather os specific variables
include_vars: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- vars
- name: include os specific tasks
include_tasks: "{{ lookup('first_found', possible_files) }}"
vars:
possible_files:
files:
- "{{ ansible_distribution }}-{{ ansible_distribution_version }}.yaml"
- "{{ ansible_distribution }}.yaml"
- "{{ ansible_os_family }}.yaml"
- "default.yaml"
paths:
- tasks
- name: install
package:
name: "{{ consul_package_name | default('consul') }}"
state: "{{ consul_package_state | default('present') }}"
- name: configure
template:
src: "{{ consul_config_template }}"
dest: "{{ consul_config_path }}"
owner: "{{ consul_config_owner }}"
group: "{{ consul_config_group }}"
mode: "{{ consul_config_mode }}"
notify: restart consul
- name: service
service:
name: "{{ consul_service_name | default('consul') }}"
state: "{{ consul_service_state | default('started') }}"
enabled: "{{ consul_service_enabled | default(true) }}"
- include: forward-unbound.yaml
when: consul_unbound_enabled

View File

@ -0,0 +1,41 @@
// {{ ansible_managed }}
data_dir = "{{ consul_data_dir }}"
{% if consul_server is defined %}
server = {{ (consul_server | lower) | default(false) }}
{% endif %}
{% if consul_bind_addr is defined %}
bind_addr = "{{ (consul_bind_addr | lower) | default("0.0.0.0") }}"
{% endif %}
{% if consul_server is true and consul_bootstrap_expect is defined %}
bootstrap_expect = {{ consul_bootstrap_expect }}
{% endif %}
{% if consul_retry_join is defined %}
retry_join = [
{%- set comma = joiner(",") -%}
{%- for x in consul_retry_join | default([]) -%}
{{ comma() }}"{{ x }}"
{%- endfor -%} ]
{% endif %}
{% if consul_server_addresses is defined %}
server_addresses = [
{%- set comma = joiner(",") -%}
{%- for x in consul_server_addresses | default([]) -%}
{{ comma() }}"{{ x }}"
{%- endfor -%} ]
{% endif %}
ui_config {
{% if consul_ui_config_enabled is defined %}
enabled = {{ (consul_ui_config_enabled | lower) | default(false) }}
{% endif %}
}
{% if consul_client_addr is defined %}
client_addr = "{{ (consul_client_addr | lower) | default("0.0.0.0") }}"
{% endif %}

View File