-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-node_exporter.yml
100 lines (100 loc) · 3.64 KB
/
deploy-node_exporter.yml
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
---
- name: Deploy node_exporter
hosts: all
gather_facts: true
become: true
pre_tasks:
- name: Determine whether cert renewal should be forced
set_fact:
renew_cert: "{{ force_cert_renewal | default(false) }}"
- name: Set cert_common_name to hostname if it isn't already
set_fact:
cert_common_name: "{{ ansible_fqdn }}"
- name: Append lcmchealth.org to hostname if it isn't already
set_fact:
cert_common_name: "{{ ansible_fqdn }}.lcmchealth.org"
when: not cert_common_name is search(".lcmchealth.org")
- name: Check if install directory exists
stat:
path: "{{ install_dir }}"
register: installdir
- name: Create install directory if it doesn't exist
file:
path: "{{ install_dir }}"
state: directory
when: installdir.stat.exists == false
- name: Check if ca file exists
stat:
path: "{{ install_dir }}/ca.crt"
register: file_ca
- name: Check if cert file exists
stat:
path: "{{ install_dir }}/tls.crt"
register: file_cert
- name: Check if key file exists
stat:
path: "{{ install_dir }}/tls.key"
register: file_key
- name: Generate certificates
block:
- name: Get server name (GATHER_FACTS MUST BE TRUE OR THIS WILL FAIL)
set_fact:
server_name: "{{ cert_common_name | lower }}"
- name:
uri:
url: "{{ lookup('env','VAULT_ADDR') }}/v1/auth/approle/login"
method: POST
return_content: true
headers:
accept: application/json
body_format: json
body:
role_id: "{{ lookup('env','ROLE_ID') }}"
secret_id: "{{ lookup('env','SECRET_ID') }}"
status_code: 200
register: vault_auth
delegate_to: localhost
- name:
uri:
url: "{{ lookup('env','VAULT_ADDR') }}/v1/prompki/issue/server"
method: POST
return_content: true
headers:
accept: application/json
X-Vault-Token: "{{ vault_auth.json.auth.client_token }}"
body_format: json
body:
common_name: "{{ server_name }}"
alt_names: "{{ server_name }}"
private_key_format: "pkcs8"
ttl: "{{ cert_ttl }}"
format: "pem"
status_code: 200
register: cert
delegate_to: localhost
#- name:
# debug:
# msg: "{{ cert.json }}"
- name: Write ca file
copy:
content: "{{ cert.json.data.issuing_ca }}"
dest: "{{ install_dir }}/ca.crt"
- name: Write cert file
copy:
content: "{{ cert.json.data.certificate }}"
dest: "{{ install_dir }}/tls.crt"
- name: Write key file
copy:
content: "{{ cert.json.data.private_key }}"
dest: "{{ install_dir }}/tls.key"
when: file_ca.stat.exists == false or file_cert.stat.exists == false or file_key.stat.exists == false or renew_cert == true
#- name: Create config.yml
# template:
# src: "{{ prometheus_config | default('config.yml.j2') }}"
# dest: "{{ install_dir }}/config.yml"
#- name: Create web-config.yml
# template:
# src: web-config.yml.j2
# dest: "{{ install_dir }}/web-config.yml"
roles:
- prometheus.prometheus.node_exporter