<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core<br>
(It concerns strings encrypted via <code class="notranslate">ansible-vault</code>.)</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.1.0
  config file = /home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg
  configured module search path = [u'/home/flaf/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]"><pre class="notranslate"><code class="notranslate">ansible 2.4.1.0
  config file = /home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg
  configured module search path = [u'/home/flaf/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ANSIBLE_NOCOWS(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = True
DEFAULT_BECOME(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = [u'/home/flaf/MesDocs/informatique/docs/mes_n
DEFAULT_ROLES_PATH(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = [u'/home/flaf/MesDocs/informatique/docs/mes_"><pre class="notranslate"><code class="notranslate">ANSIBLE_NOCOWS(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = True
DEFAULT_BECOME(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = [u'/home/flaf/MesDocs/informatique/docs/mes_n
DEFAULT_ROLES_PATH(/home/flaf/MesDocs/informatique/docs/mes_notes/git/ansible-tice/ansible.cfg) = [u'/home/flaf/MesDocs/informatique/docs/mes_
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.2 (stretch)
Release:	9.2
Codename:	stretch"><pre class="notranslate"><code class="notranslate">~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.2 (stretch)
Release:	9.2
Codename:	stretch
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">If a string variable is encrypted via <code class="notranslate">ansible-vault</code>, its type is not string.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Here is the playbook to reproduce the problem:</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:
    key1: 'abcdef'
    # key2 is equal to 'abcdef' too but encrypted via `ansible-vault`.
    key2: !vault |
          $ANSIBLE_VAULT;1.1;AES256
          65326230313463613961666434396131646432343565333835383433336436653661643835363336
          3133653264363162376164373630343238353833383631370a616632303532666161643936383266
          30623564373335633431323532313264366533313366626635303963303431383135633435303364
          3036333436663037650a373336643666313761653564393963313162616339643436316463313938
          3664
  tasks:
    - debug:
        msg: 'value of key1 =&gt; {{ key1 }}'
    - debug:
        msg: 'value of key2 =&gt; {{ key2 }}'
    - debug:
        msg: 'result of the test [key1 is string] =&gt; {{ key1 is string }}'
    - debug:
        msg: 'result of the test [(key1 | length) &gt; 0] =&gt; {{ (key1 | length) &gt; 0 }}'
    - debug:
        msg: 'result of the test [key2 is string] =&gt; {{ key2 is string }}'
    - debug:
        msg: 'result of the test [(key2 | length) &gt; 0] =&gt; {{ (key2 | length) &gt; 0 }}'"><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">key1</span>: <span class="pl-s"><span class="pl-pds">'</span>abcdef<span class="pl-pds">'</span></span>
    <span class="pl-c"><span class="pl-c">#</span> key2 is equal to 'abcdef' too but encrypted via `ansible-vault`.</span>
    <span class="pl-ent">key2</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">          65326230313463613961666434396131646432343565333835383433336436653661643835363336</span>
<span class="pl-s">          3133653264363162376164373630343238353833383631370a616632303532666161643936383266</span>
<span class="pl-s">          30623564373335633431323532313264366533313366626635303963303431383135633435303364</span>
<span class="pl-s">          3036333436663037650a373336643666313761653564393963313162616339643436316463313938</span>
<span class="pl-s">          3664</span>
<span class="pl-s"></span>  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>value of key1 =&gt; {{ key1 }}<span class="pl-pds">'</span></span>
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>value of key2 =&gt; {{ key2 }}<span class="pl-pds">'</span></span>
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>result of the test [key1 is string] =&gt; {{ key1 is string }}<span class="pl-pds">'</span></span>
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>result of the test [(key1 | length) &gt; 0] =&gt; {{ (key1 | length) &gt; 0 }}<span class="pl-pds">'</span></span>
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>result of the test [key2 is string] =&gt; {{ key2 is string }}<span class="pl-pds">'</span></span>
    - <span class="pl-ent">debug</span>:
        <span class="pl-ent">msg</span>: <span class="pl-s"><span class="pl-pds">'</span>result of the test [(key2 | length) &gt; 0] =&gt; {{ (key2 | length) &gt; 0 }}<span class="pl-pds">'</span></span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">According to me, the expected result should be:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="### Warning this is not the real case. ###
~$ ansible-playbook --ask-vault-pass /tmp/playbook.yaml 
Vault password: 

PLAY [localhost] ****************************************************************

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;value of key1 =&gt; abcdef&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;value of key2 =&gt; abcedf&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [key1 is string] =&gt; True&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [(key1 | length) &gt; 0] =&gt; True&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [key2 is string] =&gt; True&quot; ### [1] ###
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [(key2 | length) &gt; 0] =&gt; True&quot; ### [2] ###
}

PLAY RECAP **********************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=0  "><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span>## Warning this is not the real case. ###</span>
<span class="pl-k">~</span>$ ansible-playbook --ask-vault-pass /tmp/playbook.yaml 
Vault password: 

PLAY [localhost] <span class="pl-k">****************************************************************</span>

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>value of key1 =&gt; abcdef<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>value of key2 =&gt; abcedf<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [key1 is string] =&gt; True<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [(key1 | length) &gt; 0] =&gt; True<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [key2 is string] =&gt; True<span class="pl-pds">"</span></span> <span class="pl-c"><span class="pl-c">#</span>## [1] ###</span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [(key2 | length) &gt; 0] =&gt; True<span class="pl-pds">"</span></span> <span class="pl-c"><span class="pl-c">#</span>## [2] ###</span>
}

PLAY RECAP <span class="pl-k">**********************************************************************</span>
localhost                  <span class="pl-c1">:</span> ok=6    changed=0    unreachable=0    failed=0  </pre></div>
<p dir="auto">See carefully the tasks with the mention <code class="notranslate">### [1] ###</code> and <code class="notranslate">### [2] ###</code>. The result is different is the real case below.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">But the result is:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="### Here is the real case. ###
~$ ansible-playbook --ask-vault-pass /tmp/playbook.yaml 
Vault password: 

PLAY [localhost] ****************************************************************

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;value of key1 =&gt; abcdef&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;value of key2 =&gt; abcedf&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [key1 is string] =&gt; True&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [(key1 | length) &gt; 0] =&gt; True&quot;
}

TASK [debug] ********************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;result of the test [key2 is string] =&gt; False&quot; ### [1] ###
}

TASK [debug] ********************************************************************
fatal: [localhost]: FAILED! =&gt; {&quot;msg&quot;: &quot;Unexpected templating type error occurred
on (result of the test [(key2 | length) &gt; 0] =&gt; {{ (key2 | length) &gt; 0 }}): object of type
'AnsibleVaultEncryptedUnicode' has no len()&quot;}
	to retry, use: --limit @/tmp/playbook.retry ### [2] ###

PLAY RECAP **********************************************************************
localhost                  : ok=5    changed=0    unreachable=0    failed=1"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span>## Here is the real case. ###</span>
<span class="pl-k">~</span>$ ansible-playbook --ask-vault-pass /tmp/playbook.yaml 
Vault password: 

PLAY [localhost] <span class="pl-k">****************************************************************</span>

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>value of key1 =&gt; abcdef<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>value of key2 =&gt; abcedf<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [key1 is string] =&gt; True<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [(key1 | length) &gt; 0] =&gt; True<span class="pl-pds">"</span></span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
ok: [localhost] =<span class="pl-k">&gt;</span> {
    <span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>result of the test [key2 is string] =&gt; False<span class="pl-pds">"</span></span> <span class="pl-c"><span class="pl-c">#</span>## [1] ###</span>
}

TASK [debug] <span class="pl-k">********************************************************************</span>
fatal: [localhost]: FAILED<span class="pl-k">!</span> =<span class="pl-k">&gt;</span> {<span class="pl-s"><span class="pl-pds">"</span>msg<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Unexpected templating type error occurred</span>
<span class="pl-s">on (result of the test [(key2 | length) &gt; 0] =&gt; {{ (key2 | length) &gt; 0 }}): object of type</span>
<span class="pl-s">'AnsibleVaultEncryptedUnicode' has no len()<span class="pl-pds">"</span></span>}
	to retry, use: --limit @/tmp/playbook.retry <span class="pl-c"><span class="pl-c">#</span>## [2] ###</span>

PLAY RECAP <span class="pl-k">**********************************************************************</span>
localhost                  <span class="pl-c1">:</span> ok=5    changed=0    unreachable=0    failed=1</pre></div>
<p dir="auto">There are differences in the 2 last tasks.</p>
<p dir="auto">Regards.</p>
<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>