File tree Expand file tree Collapse file tree 4 files changed +84
-16
lines changed Expand file tree Collapse file tree 4 files changed +84
-16
lines changed Original file line number Diff line number Diff line change @@ -31,8 +31,38 @@ s (default: Omitted)
31
31
* ` vault_extra_volumes ` : List of ` "<host_location>:<container_mountpoint>" `
32
32
* ` vault_tls_key ` : Path to TLS key to use by Vault
33
33
* ` vault_tls_cert ` : Path to TLS cert to use by Vault
34
+ * ` vault_log_keys ` : Whether to log the root token and unseal keys in the Ansible output. Default ` false `
35
+ * ` vault_set_keys_fact ` : Whether to set a ` vault_keys ` fact containing the root token and unseal keys. Default ` false `
36
+ * ` vault_write_keys_file ` : Whether to write the root token and unseal keys to a file. Default ` false `
37
+ * ` vault_write_keys_file_host ` : Host on which to write root token and unseal keys. Default ` localhost `
38
+ * ` vault_write_keys_file_path ` : Path of file to write root token and unseal keys. Default ` vault-keys.json `
34
39
40
+ Root and unseal keys
41
+ --------------------
35
42
43
+ After Vault has been initialised, a root token and a set of unseal keys are emitted.
44
+ It is very important to store these keys safely and securely.
45
+ This role provides several mechanisms for extracting the root token and unseal keys:
46
+
47
+ 1 . Print to Ansible log output (` vault_log_keys ` )
48
+ 1 . Set a ` vault_keys ` fact (` vault_set_keys_fact ` )
49
+ 1 . Write to a file (` vault_write_keys_file ` )
50
+
51
+ In each case, the output will contain the following:
52
+
53
+ ``` json
54
+ {
55
+ "keys" : [
56
+ " ..." ,
57
+ " ..."
58
+ ],
59
+ "keys_base64" : [
60
+ " ..." ,
61
+ " ..."
62
+ ],
63
+ "root_token" : " ..."
64
+ }
65
+ ```
36
66
37
67
Example playbook (used with OpenStack Kayobe)
38
68
---------------------------------------------
Original file line number Diff line number Diff line change @@ -68,3 +68,16 @@ consul_extra_volumes: []
68
68
# Combined volume lists
69
69
_vault_volumes : " {{ _vault_default_volumes + vault_extra_volumes }}"
70
70
_consul_volumes : " {{ _consul_default_volumes + consul_extra_volumes }}"
71
+
72
+ # Whether to log the root token and unseal keys in the Ansible output.
73
+ vault_log_keys : false
74
+
75
+ # Whether to set a vault_keys fact containing the root token and unseal keys.
76
+ vault_set_keys_fact : false
77
+
78
+ # Whether to write the root token and unseal keys to a file.
79
+ vault_write_keys_file : false
80
+ # Host on which to write root token and unseal keys.
81
+ vault_write_keys_file_host : localhost
82
+ # Path of file to write root token and unseal keys.
83
+ vault_write_keys_file_path : vault-keys.json
Original file line number Diff line number Diff line change 22
22
register : vault_init_status
23
23
retries : 50
24
24
delay : 1
25
+ run_once : true
25
26
until : vault_init_status.status == 200
26
27
27
- - name : Initialize vault
28
- hashivault_init :
29
- url : " {{ vault_api_addr }}"
30
- run_once : True
31
- no_log : True
32
- when : not vault_init_status.json.initialized
33
- register : vault_keys
28
+ - block :
29
+ - name : Initialize vault
30
+ hashivault_init :
31
+ url : " {{ vault_api_addr }}"
32
+ no_log : true
33
+ register : vault_keys_result
34
34
35
- - name : Print vault keys
36
- debug :
37
- var : vault_keys
38
- when : not vault_init_status.json.initialized
35
+ - name : Print vault keys
36
+ debug :
37
+ var : vault_keys_result
38
+ when :
39
+ - vault_log_keys | bool
39
40
41
+ - name : Set vault_keys fact
42
+ set_fact :
43
+ vault_keys : " {{ vault_keys_result }}"
44
+ when :
45
+ - vault_set_keys_fact | bool
46
+
47
+ - name : Write vault keys to a file
48
+ copy :
49
+ content : " {{ vault_keys_result | to_nice_json }}"
50
+ dest : " {{ vault_write_keys_file_path }}"
51
+ mode : 0600
52
+ delegate_to : " {{ vault_write_keys_file_host }}"
53
+ when :
54
+ - vault_write_keys_file | bool
55
+ run_once : true
56
+ when :
57
+ - not vault_init_status.json.initialized
Original file line number Diff line number Diff line change 2
2
- name : Prepare for vault role
3
3
gather_facts : True
4
4
hosts : consul
5
+ vars :
6
+ consul_bind_interface : lo
7
+ vault_bind_address : 127.0.0.1
8
+ vault_api_addr : http://127.0.0.1:8200
9
+ vault_config_dir : " /etc/vault"
10
+ vault_log_keys : true
11
+ vault_set_keys_fact : true
12
+ vault_write_keys_file : true
5
13
tasks :
6
14
- name : Ensure /etc/vault exists
7
15
file :
11
19
12
20
- include_role :
13
21
name : vault
14
- vars :
15
- consul_bind_interface : lo
16
- vault_bind_address : 127.0.0.1
17
- vault_api_addr : http://127.0.0.1:8200
18
- vault_config_dir : " /etc/vault"
22
+
23
+ # Idempotence test
24
+ - include_role :
25
+ name : vault
You can’t perform that action at this time.
0 commit comments