adds consul configuration role

This commit is contained in:
James Hackett 2022-12-08 01:57:33 +00:00
parent 2185a79d8f
commit c5281bd0fb
2 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,28 @@
---
- name: Copy consul base configuration
become: true
template:
src: consul.hcl.j2
dest: /etc/consul.d/consul.hcl
owner: consul
group: consul
mode: 0640
- name: Copy consul-server configuration
become: true
template:
src: consul-server.hcl.j2
dest: /etc/consul.d/consul-server.hcl
owner: consul
group: consul
mode: 0640
- name: Copy consul systemd unit file
become: true
template:
src: consul.service
dest: /etc/systemd/system/consul.service
owner: root
group: root
mode: 0644

View file

@ -0,0 +1,43 @@
---
- name: Install or update consul
become: true
apt:
name: consul
state: latest
update_cache: yes
- name: Add consul user
become: true
user:
name: consul
system: yes
shell: /bin/false
- name: Create consul directories
become: true
file:
path: "{{ item }}"
state: directory
owner: consul
group: consul
with_items:
- /etc/consul.d
- /opt/consul
- include_tasks: configure.yml
- name: Enable and start consul
become: true
systemd:
name: consul
enabled: yes
state: started
- name: Check if consul is running
become: true
shell: consul members
register: consul_members
- name: Print consul members
debug:
msg: "{{ consul_members.stdout_lines }}"