# Ansible Vault and Template module problem: bank characted added to the value when recovering string-vaulted variable.

**URL:** <https://forum.ansible.com/t/ansible-vault-and-template-module-problem-bank-characted-added-to-the-value-when-recovering-string-vaulted-variable/28467>\
**Category:** Ansible Project\
**Created:** [August 30, 2018, 1:53pm UTC](https://forum.ansible.com/t/ansible-vault-and-template-module-problem-bank-characted-added-to-the-value-when-recovering-string-vaulted-variable/28467 "2018-08-30T13:53:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_VA](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@David\_VA](https://forum.ansible.com/u/David_VA)\
**Post date:** [August 30, 2018, 1:53pm UTC](https://forum.ansible.com/t/ansible-vault-and-template-module-problem-bank-characted-added-to-the-value-when-recovering-string-vaulted-variable/28467/1 "2018-08-30T13:53:42Z")

</div>

Dear colleges,

In our organization we are using string-vaulted inventories in order to keep secure some sensitive information that is applied later during the play-book execution. In one of the steps some configuration files are generated. The configuration files are generated using the Template module and some Jinja2 Templates.

All the text plain variables are replaced correctly in the template. However, the string-vaulted variables are decrypted and replaced with a blank space before the correct value.

The variable vault process has been double-checked and the value provided to the ansible-vault command has no blank spaces.

Is anybody having the same problems when using Ansible Vault and Template Module?

**Example:**

Clear text inventory section:

communication\_ws\_adm\_password: admin  
communication\_ws\_adm\_password: password

Encrypt string:

ansible-vault encrypt\_string --name esearch\_copla\_client\_tomcat\_server\_password m3l0n3sdulc3S --ask-vault

Vaulted inventory section:

communication\_ws\_adm\_password: admin

communication\_ws\_adm\_password: !vault |  
$ANSIBLE\_VAULT;1.1;AES256  
31323731313536653038636138666461363833666137623539636563396337363061333262303333  
6332323961633439626562313531333836383266373261300a363966643436306436633432333135  
64303333356535353830613037393130313561366561343035636366623063646664313939383037  
6532366661643465350a323437633765386163613135373933613165363137666338646165346539  
3638

Jinja 2 Template:

adm.username={{ communication\_ws\_adm\_username }}  
adm.password={{ communication\_ws\_adm\_password }}

Result after replacement:

adm.username=admin  
adm.password= password

Kind regards. David.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 30, 2018, 9:24pm UTC](https://forum.ansible.com/t/ansible-vault-and-template-module-problem-bank-characted-added-to-the-value-when-recovering-string-vaulted-variable/28467/2 "2018-08-30T21:24:12Z")

</div>

Can't confirm with Ansible 2.6.3, if you provide the password for the vault we could have tested it.  
My password is password.

$ ansible-vault encrypt\_string --name myvar mysecret --ask-vault-pass  
New Vault password: password  
Confirm New Vault password: password  
myvar: !vault |  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ANSIBLE\_VAULT;1.1;AES256  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;35383365366233363539646466343837643262316131303763653963643665643061313632383962  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3931353436396663303931626432353261343963633935660a646136383061306566313139626263  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;32663933373538373639363435303633323966326232636632303333646638396563643438383563  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3433623865623338330a363333656266383434383332633432383238393336393364613239363865  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3539  
Encryption successful

test.yml
