<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">vault</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.2.0"><pre class="notranslate"><code class="notranslate">ansible 2.4.2.0
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Default</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">Ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">Passing encrypted variables through to_yaml results in variable not being decrypted.<br>
... through to_json results in</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;msg&quot;: &quot;Unexpected templating type error occurred on ({{ encrypted_var | to_json }}): 'decrypted_secret' is not JSON serializable&quot;"><pre class="notranslate"><code class="notranslate">"msg": "Unexpected templating type error occurred on ({{ encrypted_var | to_json }}): 'decrypted_secret' is not JSON serializable"
</code></pre></div>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">See tests added here: <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/paulbovbel/ansible/commit/25a3ee9a253708bd08d642b39ff6081406a60d37/hovercard" href="https://github.com/paulbovbel/ansible/commit/25a3ee9a253708bd08d642b39ff6081406a60d37">paulbovbel@<tt>25a3ee9</tt></a></p>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Expected tests to pass.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# ansible-test integration vault

TASK [test_vault_embedded : Assert that a embedded vault of a string with no newline works with to_yaml] **************************************************
fatal: [testhost]: FAILED! =&gt; {
    &quot;assertion&quot;: &quot;\&quot;!vault |\n  $ANSIBLE_VAULT;1.1;AES256\n  33363965326261303234626463623963633531343539616138316433353830356566396130353436\n  3562643163366231316662386565383735653432386435610a306664636137376132643732393835\n  63383038383730306639353234326630666539346233376330303938323639306661313032396437\n  6233623062366136310a633866373936313238333730653739323461656662303864663666653563\n  3138\n\&quot; == \&quot;Setec Astronomy\n...\n\&quot;&quot;, 
    &quot;changed&quot;: false, 
    &quot;evaluated_to&quot;: false
}
...ignoring

TASK [test_vault_embedded : Assert that a multi line embedded vault works with to_yaml, including new line] ***********************************************
fatal: [testhost]: FAILED! =&gt; {
    &quot;assertion&quot;: &quot;vault_encrypted_var | to_yaml == decrypted_var | to_yaml&quot;, 
    &quot;changed&quot;: false, 
    &quot;evaluated_to&quot;: false
}
...ignoring

TASK [test_vault_embedded : Assert that a embedded vault of a string with no newline works with to_yaml] **************************************************
fatal: [testhost]: FAILED! =&gt; {&quot;msg&quot;: &quot;Unexpected templating type error occurred on (\&quot;{{ vault_encrypted_one_line_var | to_json }}\&quot; == \&quot;{{ decrypted_one_line_var | to_json }}\&quot;): u'Setec Astronomy' is not JSON serializable&quot;}
...ignoring

TASK [test_vault_embedded : Assert that a multi line embedded vault works with to_yaml, including new line] ***********************************************
fatal: [testhost]: FAILED! =&gt; {
    &quot;assertion&quot;: &quot;vault_encrypted_var == decrypted_var | to_json&quot;, 
    &quot;changed&quot;: false, 
    &quot;evaluated_to&quot;: false
}"><pre class="notranslate"><code class="notranslate"># ansible-test integration vault

TASK [test_vault_embedded : Assert that a embedded vault of a string with no newline works with to_yaml] **************************************************
fatal: [testhost]: FAILED! =&gt; {
    "assertion": "\"!vault |\n  $ANSIBLE_VAULT;1.1;AES256\n  33363965326261303234626463623963633531343539616138316433353830356566396130353436\n  3562643163366231316662386565383735653432386435610a306664636137376132643732393835\n  63383038383730306639353234326630666539346233376330303938323639306661313032396437\n  6233623062366136310a633866373936313238333730653739323461656662303864663666653563\n  3138\n\" == \"Setec Astronomy\n...\n\"", 
    "changed": false, 
    "evaluated_to": false
}
...ignoring

TASK [test_vault_embedded : Assert that a multi line embedded vault works with to_yaml, including new line] ***********************************************
fatal: [testhost]: FAILED! =&gt; {
    "assertion": "vault_encrypted_var | to_yaml == decrypted_var | to_yaml", 
    "changed": false, 
    "evaluated_to": false
}
...ignoring

TASK [test_vault_embedded : Assert that a embedded vault of a string with no newline works with to_yaml] **************************************************
fatal: [testhost]: FAILED! =&gt; {"msg": "Unexpected templating type error occurred on (\"{{ vault_encrypted_one_line_var | to_json }}\" == \"{{ decrypted_one_line_var | to_json }}\"): u'Setec Astronomy' is not JSON serializable"}
...ignoring

TASK [test_vault_embedded : Assert that a multi line embedded vault works with to_yaml, including new line] ***********************************************
fatal: [testhost]: FAILED! =&gt; {
    "assertion": "vault_encrypted_var == decrypted_var | to_json", 
    "changed": false, 
    "evaluated_to": false
}
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">vault</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="devel"><pre class="notranslate"><code class="notranslate">devel
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<h5 dir="auto">SUMMARY</h5>
<p dir="auto">A single vault encrypted value does not get decrypted in a jinja2 pipeline.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Don't worry the below vault data is just useless strings.</p>

<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---
- hosts: localhost
  gather_facts: false
  vars:
    the_password: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          66653436353263336535316333313533666563386463623562396234313064643430323066626538
          3234393066313964393861613431313832306439383633340a653361636537303033313137613933
          33653333633139353736636332333237613761636430356665383839663164363739323337643333
          6466313434306462370a663539346162623836626165343830666536646631616165636438646639
          6134
  tasks:
    - command: 'echo {{ the_password|string|type_debug }}'"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">false</span>
  <span class="pl-ent">vars</span>:
    <span class="pl-ent">the_password</span>: <span class="pl-k">!vault</span> <span class="pl-s">|</span>
<span class="pl-s">          $ANSIBLE_VAULT;1.1;AES256</span>
<span class="pl-s">          66653436353263336535316333313533666563386463623562396234313064643430323066626538</span>
<span class="pl-s">          3234393066313964393861613431313832306439383633340a653361636537303033313137613933</span>
<span class="pl-s">          33653333633139353736636332333237613761636430356665383839663164363739323337643333</span>
<span class="pl-s">          6466313434306462370a663539346162623836626165343830666536646631616165636438646639</span>
<span class="pl-s">          6134</span>
<span class="pl-s"></span>  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">command</span>: <span class="pl-s"><span class="pl-pds">'</span>echo {{ the_password|string|type_debug }}<span class="pl-pds">'</span></span></pre></div>
<p dir="auto">This outputs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;stdout&quot;: &quot;AnsibleVaultEncryptedUnicode&quot;"><pre class="notranslate"><code class="notranslate">"stdout": "AnsibleVaultEncryptedUnicode"
</code></pre></div>
<p dir="auto">This is a little bit of a contrived example, but what it shows, is that if you want to do something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- command: &quot;some_command {{ the_password|quote }}&quot;"><pre class="notranslate"><code class="notranslate">- command: "some_command {{ the_password|quote }}"
</code></pre></div>
<p dir="auto">You will end up with the <code class="notranslate">$ANSIBLE_VAULT;...</code> string instead of the decrypted value</p>

<h5 dir="auto">EXPECTED RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>