aboutsummaryrefslogtreecommitdiffstats
path: root/fdio.infra.ansible/roles/consul/tasks/main.yaml
blob: 69678f9739afca8d379ba033b67c023f0a926c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
# file: tasks/main.yaml

- name: Update Repositories Cache
  ansible.builtin.apt:
    update_cache: true
  when:
    - ansible_os_family == 'Debian'
  tags:
    - consul-inst-package

- name: Dependencies
  ansible.builtin.apt:
    name: "{{ packages | flatten(levels=1) }}"
    state: "present"
    cache_valid_time: 3600
    install_recommends: false
  when:
    - ansible_os_family == 'Debian'
  tags:
    - consul-inst-dependencies

- name: Add Consul Group
  ansible.builtin.group:
    name: "{{ consul_group }}"
    state: "present"
  tags:
    - consul-conf-user

- name: Add Consul user
  ansible.builtin.user:
    name: "{{ consul_user }}"
    group: "{{ consul_group }}"
    state: "present"
    system: true
  tags:
    - consul-conf-user

- name: Download Consul
  ansible.builtin.get_url:
    url: "{{ consul_zip_url }}"
    dest: "{{ consul_inst_dir }}/{{ consul_pkg }}"
  tags:
    - consul-inst-package

- name: Clean Consul
  ansible.builtin.file:
    path: "{{ consul_inst_dir }}/consul"
    state: "absent"
  when:
    - consul_force_update | bool
  tags:
    - consul-inst-package

- name: Unarchive Consul
  ansible.builtin.unarchive:
    src: "{{ consul_inst_dir }}/{{ consul_pkg }}"
    dest: "{{ consul_inst_dir }}/"
    remote_src: true
  tags:
    - consul-inst-package

- name: Consul
  ansible.builtin.copy:
    src: "{{ consul_inst_dir }}/consul"
    dest: "{{ consul_bin_dir }}"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    force: true
    mode: 0755
    remote_src: true
  tags:
    - consul-inst-package

- name: Create Directories
  ansible.builtin.file:
    dest: "{{ item }}"
    state: "directory"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    mode: 0755
  with_items:
    - "{{ consul_data_dir }}"
    - "{{ nomad_config_dir }}"
    - "{{ nomad_ssl_dir }}"
  tags:
    - consul-conf

- name: Base Configuration
  ansible.builtin.template:
    src: "{{ item }}.hcl.j2"
    dest: "{{ consul_config_dir }}/{{ item }}.hcl"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    mode: 0644
  with_items:
    - "base"
    - "ports"
    - "telemetry"
  tags:
    - consul-conf

- name: Copy Certificates And Keys
  ansible.builtin.copy:
    content: "{{ item.src }}"
    dest: "{{ item.dest }}"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    mode: 0600
  no_log: true
  loop: "{{ consul_certificates | flatten(levels=1) }}"
  when:
    - consul_certificates is defined
  tags:
    - consul-conf

- name: Stop Systemd-resolved
  ansible.builtin.systemd:
    daemon_reload: true
    enabled: false
    name: "systemd-resolved"
    state: "{{ systemd_resolved_state }}"
  when:
    - consul_service_mgr == "systemd"
  tags:
    - consul-conf

- name: System.d Script
  ansible.builtin.template:
    src: "consul_systemd.service.j2"
    dest: "/lib/systemd/system/consul.service"
    owner: "root"
    group: "root"
    mode: 0644
  notify:
    - "Restart Consul"
  when:
    - consul_service_mgr == "systemd"
  tags:
    - consul-conf

- name: Flush handlers
  ansible.builtin.meta: flush_handlers