ansible-consul/tasks/main.yml
2022-03-26 11:41:13 +01:00

69 lines
1.6 KiB
YAML

---
- 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: encure data dir exist
file:
state: directory
owner: consul
path: "{{ consul_data_dir }}"
mode: 0755
- name: apply config template
block:
- name: server template
template:
src: config.hcl.j2
dest: /etc/consul.d/config.hcl
owner: consul
mode: 0644
notify: reload consul configuration
- name: systemd consul resolution
block:
- name: create resolved.conf.d folder
file:
state: directory
path: /etc/systemd/resolved.conf.d
owner: root
group: root
mode: 0755
- name: consul resolution file
template:
src: resolved.conf.d/consul.conf.j2
dest: /etc/systemd/resolved.conf.d/consul.conf
owner: root
group: root
mode: 0644
- name: configure backup
block:
- name: copy backup script
copy:
dest: "{{ consul_data_dir }}/cs-backup.sh"
mode: 0744
owner: consul
src: cs-backup.sh
- name: consul snaphot cron.d
cron:
name: consul backup
user: consul
state: present
job: "{{ consul_data_dir }}/cs-backup.sh {{ consul_backup_location }}"
hour: "{{consul_cron_hour}}"
when: consul_snapshot
- name: ensure service is started
systemd:
name: "{{ consul_service_name }}"
state: started
enabled: True