Skip to content

Commit 8f2013c

Browse files
authored
Merge pull request #37 from stackhpc/fix_defaults
Add default values for critical variables
2 parents b65bd9b + f3f84c2 commit 8f2013c

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

roles/vault/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ Role variables
1313
--------------
1414

1515
* Consul
16-
* Mandatory
17-
* `consul_bind_interface`: Which interface should be used for Consul
1816
* Optional
17+
* `consul_bind_interface`: Which interface should be used for Consul (default: "lo")
1918
* `consul_docker_name`: Docker - under which name to run the Consul image (default: "consul")
2019
* `consul_docker_image`: Docker image for Consul (default: "consul")
2120
* `consul_docker_tag`: Docker image tag for Consul (default: "latest")
@@ -26,10 +25,10 @@ Role variables
2625
* Vault
2726
* Mandatory
2827
* `vault_cluster_name`: Vault cluster name (e.g. "prod_cluster")
29-
* `vault_api_addr`: Vault [API addr](https://www.vaultproject.io/docs/configuration#api_addr) - Full URL including protocol and port (e.g. "http://127.0.0.1:8200")
30-
* `vault_bind_address`: Which IP address should Vault bind to
3128
* `vault_config_dir`: Directory into which to bind mount Vault configuration
3229
* Optional
30+
* `vault_bind_address`: Which IP address should Vault bind to (default: "127.0.0.1")
31+
* `vault_api_addr`: Vault [API addr](https://www.vaultproject.io/docs/configuration#api_addr) - Full URL including protocol and port (default: "http://127.0.0.1:8200")
3332
* `consul_container.etc_hosts`: Dict; `{<hostname>:<ip_address>}` to be added to container /etc/host
3433
s (default: Omitted)
3534
* `vault_extra_volumes`: List of `"<host_location>:<container_mountpoint>"`

roles/vault/defaults/main.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ vault_docker_image: "vault"
99
vault_docker_tag: "latest"
1010

1111
vault_cluster_name: ""
12+
vault_protocol: "{{ 'https' if vault_tls_key and vault_tls_cert else 'http' }}"
1213
# Allow vault_vip_url and vault_vip_address for backwards compatibility.
13-
vault_vip_address: "{{ vault_vip_url | default('') }}"
14-
vault_api_addr: "{{ ('https://' ~ vault_vip_address ~ ':8200') if vault_vip_address else '' }}"
15-
vault_bind_address: ""
14+
vault_vip_address: "{{ vault_vip_url | default(vault_bind_address) }}"
15+
vault_api_addr: "{{ vault_protocol ~ '://' ~ vault_vip_address ~ ':8200' }}"
16+
vault_bind_address: "127.0.0.1"
1617
vault_tls_key: ""
1718
vault_tls_cert: ""
1819

@@ -54,7 +55,7 @@ vault_config: >
5455
}
5556
}
5657
57-
consul_bind_interface: ""
58+
consul_bind_interface: "lo"
5859
consul_bind_ip: "{{ hostvars[inventory_hostname].ansible_facts[consul_bind_interface].ipv4.address }}"
5960

6061
# Docker options
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
---
22
# Allow vault_vip_url and vault_vip_address for backwards compatibility.
3-
vault_vip_address: "{{ vault_vip_url | default('') }}"
4-
vault_api_addr: "{{ ('https://' ~ vault_vip_address ~ ':8200') if vault_vip_address else '' }}"
3+
vault_protocol: "https"
4+
vault_vip_address: "{{ vault_vip_url | default(vault_bind_address) }}"
5+
vault_api_addr: "{{ vault_protocol ~ '://' ~ vault_vip_address ~ ':8200' }}"
6+
vault_bind_address: "127.0.0.1"
57

68
# List of unseal key shards.
79
vault_unseal_keys: []

roles/vault_unseal/tasks/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
username: "{{ vault_unseal_username | default(omit) }}"
2222
verify: "{{ vault_unseal_verify | default(omit) }}"
2323

24-
- name: Fail if vault is sealed (something went wrong)
24+
- name: Check if vault is sealed
2525
uri:
2626
url: "{{ vault_api_addr }}/v1/sys/seal-status"
2727
register: vault_seal_status
28-
failed_when: vault_seal_status.json.sealed
28+
29+
- name: Fail when vault is still sealed
30+
assert:
31+
that: not vault_seal_status.json.sealed
32+
fail_msg: "Vault is sealed - something went wrong"

tests/test_vault.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
gather_facts: true
44
hosts: consul
55
vars:
6-
consul_bind_interface: lo
7-
vault_bind_address: 127.0.0.1
8-
vault_api_addr: http://127.0.0.1:8200
96
vault_config_dir: "/etc/vault"
107
vault_log_keys: true
118
vault_set_keys_fact: true
@@ -29,6 +26,7 @@
2926
name: vault_unseal
3027
vars:
3128
vault_unseal_keys: "{{ vault_keys.keys_base64 }}"
29+
vault_protocol: "http"
3230

3331
- name: Configure PKI
3432
import_role:

0 commit comments

Comments
 (0)