ansible-modules-hashivault
ansible-modules-hashivault copied to clipboard
Key in write data does not expand
Sample:
- hosts: localhost
vars:
- key: "key123"
- value: "value123"
tasks:
- hashivault_write:
secret: "/cesta/k/jebnutemu/secretu"
data:
"{{ key }}": "{{ value }}"
$ vault read /cesta/k/jebnutemu/secretu
Key Value
--- -----
refresh_interval 168h0m0s
{{ key }} value123
I've seen this before and it is really an ansible issue:
https://github.com/ansible/ansible/issues/17324
On Sun, Mar 12, 2017 at 3:11 PM, michalmedvecky [email protected] wrote:
Sample:
- hosts: localhost vars:
- key: "key123"
- value: "value123" tasks:
- hashivault_write: secret: "/cesta/k/jebnutemu/secretu" data: "{{ key }}": "{{ value }}"
$ vault read /cesta/k/jebnutemu/secretu Key Value
refresh_interval 168h0m0s {{ key }} value123
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/TerryHowe/ansible-modules-hashivault/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGWsTB7evuKK2ItSuSFd5MMl94N_mz6ks5rlF99gaJpZM4MarUw .
Okay for desperates like me, one can do
- hosts: localhost
vars:
- key: "key123"
- value: "value123"
tasks:
- hashivault_write:
secret: "/cesta/k/jebnutemu/secretu"
data:
"{'{{ key }}': '{{ value }}'}"
In theory this should work too:
- hosts: localhost
vars:
- key: &key "key123"
- value: "value123"
tasks:
- hashivault_write:
secret: "/cesta/k/jebnutemu/secretu"
data:
*key: "{{ value }}"
Hard to use with with_items
though
Reopening this to document this common issue
For info, I used this way:
- hosts: localhost
vars:
- key: "key123"
- value: "value123"
tasks:
- hashivault_write:
secret: my-secret
data: "{{ my_new_data }}"
version: 2
vars:
my_new_data: "{{ {key:value} }}"
you can even loop with that I guess
we can use set_fact
to fix this like this.
@TerryHowe @absynth76 @michalmedvecky
tasks:
- set_fact:
vaultdata: "{{ vaultdata | default({}) | combine ({ item.name : item.value }) }}"
with_items:
- "{{envs}}"
- name: add secrets in hashicorp vault
hashivault_secret:
version: 2
secret: "{{env}}/tyk"
data: "{{vaultdata}}"