From c5281bd0fb13cd6ee190045ad1bf0d35161a4be4 Mon Sep 17 00:00:00 2001 From: James Hackett Date: Thu, 8 Dec 2022 01:57:33 +0000 Subject: [PATCH] adds consul configuration role --- .../configure-consul/tasks/configure.yml | 28 ++++++++++++ ansible/roles/configure-consul/tasks/main.yml | 43 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 ansible/roles/configure-consul/tasks/configure.yml create mode 100644 ansible/roles/configure-consul/tasks/main.yml diff --git a/ansible/roles/configure-consul/tasks/configure.yml b/ansible/roles/configure-consul/tasks/configure.yml new file mode 100644 index 0000000..9389c7d --- /dev/null +++ b/ansible/roles/configure-consul/tasks/configure.yml @@ -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 diff --git a/ansible/roles/configure-consul/tasks/main.yml b/ansible/roles/configure-consul/tasks/main.yml new file mode 100644 index 0000000..e20eaf3 --- /dev/null +++ b/ansible/roles/configure-consul/tasks/main.yml @@ -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 }}"