Ansible Filter to_yaml and encrypted values
Initial state
Variable
kibana_config_yml:
server.name: kibana
server.host: "0"
...
elasticsearch.username: "kibanaserver"
elasticsearch.password: !vault |
$ANSIBLE_VAULT;1.1;AES256
65653662323563643132363436646335323539343530333361656432656333373034346234636462
...
- name: "ELK service: upload kibana.yml"
copy:
content: "{{ kibana_config_yml | to_yaml }}"
dest: "/home/{{ ansible_ssh_user }}/kibana/config/kibana.yml"
Problem
Value is encrypted string in destination file
cat ./kibana/config/kibana.yml
$
server.name: kibana
server.host: 0
elasticsearch.username: kibanaserver
elasticsearch.password: !vault |
$ANSIBLE_VAULT;1.1;AES256
65653662323563643132363436646335323539343530333361656432656333373034346234636462
...
Solution
User different variable inside variable used filer to_yaml
kibana_elasticsearch_password: !vault |
$ANSIBLE_VAULT;1.1;AES256
65653662323563643132363436646335323539343530333361656432656333373034346234636462
...
kibana_config_yml:
server.name: kibana
server.host: "0"
elasticsearch.username: "kibanaserver"
elasticsearch.password: "{{ kibana_elasticsearch_password }}"