<p dir="auto">When creating variable inside tasks(using set_fact), even using "|int" filter, result passed to jinja is still string.<br>
I've created full Proof Of Concept bug in github repo : <a href="https://github.com/rafaltrojniak/ansible-jinja-casting">https://github.com/rafaltrojniak/ansible-jinja-casting</a></p>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">��Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">ansible 1.4.5</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Debian 6.0.8</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">When creating variable inside tasks(using set_fact), even using "|int" filter, result passed to jinja is still string.</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">I've created full Proof Of Concept bug in github repo : <a href="https://github.com/rafaltrojniak/ansible-jinja-casting">https://github.com/rafaltrojniak/ansible-jinja-casting</a>. To reproduce :</p>
<ul dir="auto">
<li>Clone the repo and "cd" into it</li>
<li>Set ssh access to localhost, so ansible could run</li>
<li>Run ansible-playbook  site.yml -i hosts</li>
</ul>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">I expect all templates to be generated sucessfully.<br>
All multiplication results in templates should equal 10<br>
All additions results in templates  should equal 11</p>
<h5 dir="auto">Actual Results:</h5>
<ul dir="auto">
<li>Variables in jinja seams to be string objects</li>
<li>Multiplication of strings result in repetitions of string, not mathematical multiplication</li>
<li>Addition to string result in fatal error</li>
</ul>
<p dir="auto">Here's the playbook with the problem:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Setup some config
  template: src=some.j2 dest=/vagrant/some
  register: some

- name: Setup boolean fact
  set_fact: it_is_so={{some.changed}}

- name: Setup other config
  template: src=other.j2 dest=/vagrant/other"><pre class="notranslate"><code class="notranslate">- name: Setup some config
  template: src=some.j2 dest=/vagrant/some
  register: some

- name: Setup boolean fact
  set_fact: it_is_so={{some.changed}}

- name: Setup other config
  template: src=other.j2 dest=/vagrant/other
</code></pre></div>
<p dir="auto">Here's the <code class="notranslate">other.j2</code> template:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Say...
{% if it_is_so %}
it is so
{% else %}
it isn't so
{% endif %}"><pre class="notranslate"><code class="notranslate">Say...
{% if it_is_so %}
it is so
{% else %}
it isn't so
{% endif %}
</code></pre></div>
<p dir="auto">The issue I'm having is that the <code class="notranslate">other.j2</code> template has a check which assumed that the <code class="notranslate">it_is_so</code> variable is a boolean.  As it turns out, that's not the case, instead, it's a string.  So even if <code class="notranslate">it_is_so</code> was set to "False" it would still be considered true when parsing the template.</p>
<p dir="auto">I do want to note that it is treated as a boolean if I changed it up to:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Setup boolean fact
  set_fact: 
      it_is_so: ${some.changed}"><pre class="notranslate"><code class="notranslate">- name: Setup boolean fact
  set_fact: 
      it_is_so: ${some.changed}
</code></pre></div>
<p dir="auto">I couldn't get away with <code class="notranslate">{{some.changed}}</code>, because it's a YAML syntax error.  This works, which is nice, but the syntax is deprecated.</p>
<p dir="auto">EDIT:</p>
<p dir="auto">Also, the <code class="notranslate">when</code> statement is able to treat the "False" string as a <code class="notranslate">false</code> boolean value.</p>