Skip to content

Commit fd0b10b

Browse files
authored
Allow the full vault_vip_address to be specified (#5)
* Use http if no vault tls key defined * Use full url rather than just addess * Catch vault_bind_url in vault_config * Use vault_api_addr not vault_vip_address * Allow backwards compatible variable names
1 parent f3ebe8c commit fd0b10b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

roles/vault/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Role variables
1818
* Vault
1919
* Mandatory
2020
* `vault_cluster_name`: Vault cluster name (e.g. "prod_cluster")
21+
* `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")
2122
* `vault_bind_address`: Which IP address should Vault bind to
22-
* `vault_vip_address`: Under which IP address Vault should be available (this role does not deploy keepalived)
2323
* `vault_tls_key`: Path to TLS key to use by Vault
2424
* `vault_tls_cert`: Path to TLS cert to use by Vault
2525
* `vault_config_dir`: Directory into which to bind mount Vault configuration
@@ -73,7 +73,7 @@ Example playbook (used with OpenStack Kayobe)
7373
consul_bind_ip: "{{ internal_net_ips[ansible_hostname] }}"
7474
consul_vip_address: "{{ internal_net_vip_address }}"
7575
vault_bind_address: "{{ external_net_ips[ansible_hostname] }}"
76-
vault_vip_address: "{{ external_net_fqdn }}"
76+
vault_api_addr: "https://{{ external_net_fqdn }}:8200"
7777
vault_config_dir: "/opt/kayobe/vault"
7878
```
7979

roles/vault/defaults/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ vault_docker_image: "vault"
99
vault_docker_tag: "latest"
1010

1111
vault_cluster_name: ""
12-
# Allow vault_vip_url for backwards compatibility.
12+
# Allow vault_vip_url and vault_vip_address for backwards compatibility.
1313
vault_vip_address: "{{ vault_vip_url | default('') }}"
14+
vault_api_addr: "{{ ('https://' ~ vault_vip_address ~ ':8200') if vault_vip_address else '' }}"
1415
vault_bind_address: ""
1516
vault_tls_key: ""
1617
vault_tls_cert: ""
@@ -21,7 +22,7 @@ vault_config: >
2122
{
2223
"cluster_name": "{{ vault_cluster_name }}",
2324
"ui": true,
24-
"api_addr": "https://{{ vault_vip_url }}:8200",
25+
"api_addr": "{{ vault_api_addr }}",
2526
"listener": [{
2627
"tcp": {
2728
"address": "{{ vault_bind_address }}:8200",

roles/vault/tasks/vault.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717

1818
- name: Check if vault is initialized
1919
uri:
20-
url: "https://{{ vault_vip_address }}:8200/v1/sys/init"
20+
url: "{{ vault_api_addr }}/v1/sys/init"
2121
register: vault_init_status
2222
retries: 50
2323
delay: 1
2424
until: vault_init_status.status == 200
2525

2626
- name: Initialize vault
27-
command: "docker exec -e 'VAULT_ADDR=https://{{ vault_vip_address }}:8200' {{ vault_docker_name }} vault operator init -format yaml"
27+
command: "docker exec -e 'VAULT_ADDR={{ vault_api_addr }}' {{ vault_docker_name }} vault operator init -format yaml"
2828
when: not vault_init_status.json.initialized
2929
run_once: True
3030
register: vault_init_output

0 commit comments

Comments
 (0)