2020-08-20 04:02:35 +00:00
|
|
|
---
|
2020-08-21 04:26:07 +00:00
|
|
|
- name: ensure consul group
|
|
|
|
group:
|
|
|
|
name: consul
|
|
|
|
state: present
|
|
|
|
system: True
|
|
|
|
|
|
|
|
- name: ensure consul user
|
|
|
|
user:
|
|
|
|
name: consul
|
|
|
|
state: present
|
|
|
|
group: consul
|
|
|
|
system: True
|
|
|
|
|
|
|
|
- name: ensure consul config dir
|
|
|
|
file:
|
|
|
|
path: /usr/local/etc/consul.d/
|
|
|
|
state: directory
|
|
|
|
owner: consul
|
|
|
|
group: consul
|
|
|
|
mode: 0755
|
|
|
|
|
2020-08-27 19:23:27 +00:00
|
|
|
- name: ensure consul config dir
|
|
|
|
file:
|
|
|
|
path: /usr/local/etc/consul.d/certs
|
|
|
|
state: directory
|
|
|
|
owner: consul
|
|
|
|
group: consul
|
2020-08-30 00:22:52 +00:00
|
|
|
mode: 0755
|
2020-08-27 19:23:27 +00:00
|
|
|
|
2020-08-30 00:22:52 +00:00
|
|
|
- name: check if server cert is expiring in the next 5 days
|
|
|
|
shell: "openssl x509 -checkend 432000 -noout -in /usr/local/etc/consul.d/certs/consul-server.pem"
|
|
|
|
args:
|
|
|
|
executable: /usr/local/bin/bash
|
|
|
|
failed_when: False
|
|
|
|
check_mode: False
|
|
|
|
changed_when: False
|
|
|
|
register: exp
|
2020-08-27 19:23:27 +00:00
|
|
|
|
2020-08-30 00:22:52 +00:00
|
|
|
- name: get cert
|
2020-10-01 02:16:38 +00:00
|
|
|
shell: "vault write pki_int/issue/{{ vault_pki_policy }} common_name=server.{{ main_dc_name }}.{{ consul_domain }} alt_names=consul.service.{{ consul_domain }},consul.service.{{ main_dc_name }}.{{ consul_domain }} ttl=43200m"
|
2020-08-30 00:22:52 +00:00
|
|
|
args:
|
|
|
|
executable: /usr/local/bin/bash
|
|
|
|
environment:
|
2020-10-17 05:09:24 +00:00
|
|
|
VAULT_ADDR: https://vault.service.masked.name:8200
|
2020-08-30 00:22:52 +00:00
|
|
|
VAULT_TOKEN: "{{ lookup('file', lookup('env', 'HOME') + '/.vault-token') }}"
|
|
|
|
VAULT_FORMAT: json
|
|
|
|
register: cert_data
|
|
|
|
when: exp.rc != 0
|
2020-08-27 19:23:27 +00:00
|
|
|
|
2020-08-30 00:22:52 +00:00
|
|
|
- name: write cert data to server
|
|
|
|
copy:
|
|
|
|
content: "{{ item.content }}"
|
|
|
|
dest: "/usr/local/etc/consul.d/certs/{{ item.path }}"
|
|
|
|
mode: '{{ item.mode }}'
|
2020-08-27 19:23:27 +00:00
|
|
|
owner: consul
|
|
|
|
group: consul
|
2020-08-30 00:22:52 +00:00
|
|
|
when: cert_data.changed
|
|
|
|
loop:
|
|
|
|
- {
|
|
|
|
content: "{{ (cert_data.stdout | from_json).data.certificate }}",
|
|
|
|
path: "consul-server.pem",
|
|
|
|
mode: "0755"
|
|
|
|
}
|
|
|
|
- {
|
|
|
|
content: "{{ (cert_data.stdout | from_json).data.private_key }}",
|
|
|
|
path: "consul-server.key",
|
|
|
|
mode: "0600"
|
|
|
|
}
|
2020-08-27 19:23:27 +00:00
|
|
|
|
2020-08-21 04:26:07 +00:00
|
|
|
- name: ensure consul data dir
|
|
|
|
file:
|
|
|
|
path: /opt/consul
|
|
|
|
state: directory
|
|
|
|
owner: consul
|
|
|
|
group: consul
|
|
|
|
mode: 0755
|
|
|
|
|
2020-08-20 05:11:33 +00:00
|
|
|
- name: check consul version
|
|
|
|
shell:
|
|
|
|
cmd: "consul --version | head -1 | cut -d'v' -f2"
|
|
|
|
args:
|
2020-08-30 00:22:52 +00:00
|
|
|
executable: /usr/local/bin/bash
|
2020-08-20 05:11:33 +00:00
|
|
|
changed_when: False
|
|
|
|
failed_when: False
|
|
|
|
register: installed_consul_version
|
2020-08-27 19:23:27 +00:00
|
|
|
check_mode: False
|
2020-08-20 05:11:33 +00:00
|
|
|
|
|
|
|
- name: get consul
|
2021-07-30 03:47:41 +00:00
|
|
|
unarchive:
|
|
|
|
src: "https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_freebsd_amd64.zip"
|
|
|
|
dest: /usr/local/bin/
|
|
|
|
mode: 0755
|
|
|
|
owner: root
|
|
|
|
group: consul
|
|
|
|
remote_src: True
|
|
|
|
when: installed_consul_version.stdout != consul_version
|
2020-08-20 05:11:33 +00:00
|
|
|
|
2020-08-21 04:26:07 +00:00
|
|
|
- name: template consul config
|
|
|
|
template:
|
|
|
|
src: templates/consul.hcl.j2
|
|
|
|
dest: /usr/local/etc/consul.d/consul.hcl
|
2020-08-20 05:11:33 +00:00
|
|
|
owner: root
|
2020-08-30 00:22:52 +00:00
|
|
|
group: consul
|
|
|
|
mode: 0750
|
2020-08-21 04:26:07 +00:00
|
|
|
notify: restart_consul_fbsd
|
|
|
|
|
|
|
|
- name: enable and start consul
|
|
|
|
service:
|
|
|
|
name: consul
|
|
|
|
state: started
|
2020-08-27 19:23:27 +00:00
|
|
|
enabled: True
|
2020-08-30 00:22:52 +00:00
|
|
|
...
|