<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core / vars expansion</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides```"><pre class="notranslate"><code class="notranslate">ansible 2.2.0.0
  config file =
  configured module search path = Default w/o overrides```
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu 16.04</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">A variable assignment can pass through a simple numeric value, but not a numeric value from a member of an object - in that case it gets silently converted to a string.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: localhost

  vars:
    five: 5
    nested:
      five: 5

  tasks:
    - set_fact:
        a: 5
        b: '{{ five }}'
        c: '{{ nested.five }}'

    - debug: msg=&quot;a0={{a}}&quot;
    - debug: msg=&quot;a1={{a+1}}&quot;
    - debug: msg=&quot;b0={{b}}&quot;
    - debug: msg=&quot;b1={{b+1}}&quot;
    - debug: msg=&quot;c0={{c}}&quot;
    - debug: msg=&quot;c1={{c+1}}&quot;"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>

  <span class="pl-ent">vars</span>:
    <span class="pl-ent">five</span>: <span class="pl-c1">5</span>
    <span class="pl-ent">nested</span>:
      <span class="pl-ent">five</span>: <span class="pl-c1">5</span>

  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">set_fact</span>:
        <span class="pl-ent">a</span>: <span class="pl-c1">5</span>
        <span class="pl-ent">b</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ five }}<span class="pl-pds">'</span></span>
        <span class="pl-ent">c</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ nested.five }}<span class="pl-pds">'</span></span>

    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="a0={{a}}"</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="a1={{a+1}}"</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="b0={{b}}"</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="b1={{b+1}}"</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="c0={{c}}"</span>
    - <span class="pl-ent">debug</span>: <span class="pl-s">msg="c1={{c+1}}"</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">a, b and c are the number 5; the values of a+1, b+1 and c+1 are 6.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;a0=5&quot;
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;a1=6&quot;
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;b0=5&quot;
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;b1=6&quot;
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    &quot;msg&quot;: &quot;c0=5&quot;
}

TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;Unexpected templating type error occurred on (c1={{c+1}}): coercing to Unicode: need string or buffer, int found&quot;}
	to retry, use: --limit @/home/ubuntu/vtp/ansible/bar.retry"><pre class="notranslate"><code class="notranslate">PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [set_fact] ****************************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "a0=5"
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "a1=6"
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "b0=5"
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "b1=6"
}

TASK [debug] *******************************************************************
ok: [localhost] =&gt; {
    "msg": "c0=5"
}

TASK [debug] *******************************************************************
fatal: [localhost]: FAILED! =&gt; {"failed": true, "msg": "Unexpected templating type error occurred on (c1={{c+1}}): coercing to Unicode: need string or buffer, int found"}
	to retry, use: --limit @/home/ubuntu/vtp/ansible/bar.retry
</code></pre></div>
<p dir="auto">That is, the value of c is a string not a number.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">Here is another example, this time using the <code class="notranslate">vars</code> option to the <code class="notranslate">template</code> module. The final test case, using with_items, is the actual use case which bit me.</p>
<p dir="auto">templates/test.j2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{% for i in range(num) %}
{{ i }}
{% endfor %}"><pre class="notranslate"><code class="notranslate">{% for i in range(num) %}
{{ i }}
{% endfor %}
</code></pre></div>
<p dir="auto">foo.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: localhost

  tasks:
    - name: test with direct var
      template:
        src: test.j2
        dest: /tmp/f1
      vars:
        num: 5

    - name: test with item var
      template:
        src: test.j2
        dest: '{{ item.filename }}'
      vars:
        num: '{{ item.count }}'
      with_items:
        - { filename: '/tmp/f2', count: 5 }"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">localhost</span>

  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">name</span>: <span class="pl-s">test with direct var</span>
      <span class="pl-ent">template</span>:
        <span class="pl-ent">src</span>: <span class="pl-s">test.j2</span>
        <span class="pl-ent">dest</span>: <span class="pl-s">/tmp/f1</span>
      <span class="pl-ent">vars</span>:
        <span class="pl-ent">num</span>: <span class="pl-c1">5</span>

    - <span class="pl-ent">name</span>: <span class="pl-s">test with item var</span>
      <span class="pl-ent">template</span>:
        <span class="pl-ent">src</span>: <span class="pl-s">test.j2</span>
        <span class="pl-ent">dest</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ item.filename }}<span class="pl-pds">'</span></span>
      <span class="pl-ent">vars</span>:
        <span class="pl-ent">num</span>: <span class="pl-s"><span class="pl-pds">'</span>{{ item.count }}<span class="pl-pds">'</span></span>
      <span class="pl-ent">with_items</span>:
        - <span class="pl-s">{ filename: '/tmp/f2', count: 5 }</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">In both cases, the template would be expanded with <code class="notranslate">num</code> equal to the number 5.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with direct var] ****************************************************
ok: [localhost]

TASK [test with item var] ******************************************************
failed: [localhost] (item={u'count': 5, u'filename': u'/tmp/f2'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;count&quot;: 5, &quot;filename&quot;: &quot;/tmp/f2&quot;}, &quot;msg&quot;: &quot;AnsibleError: Unexpected templating type error occurred on ({% for i in range(num) %}\n{{ i }}\n{% endfor %}\n): an integer is required&quot;}
	to retry, use: --limit @/home/ubuntu/vtp/ansible/foo.retry"><pre class="notranslate"><code class="notranslate">PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [localhost]

TASK [test with direct var] ****************************************************
ok: [localhost]

TASK [test with item var] ******************************************************
failed: [localhost] (item={u'count': 5, u'filename': u'/tmp/f2'}) =&gt; {"failed": true, "item": {"count": 5, "filename": "/tmp/f2"}, "msg": "AnsibleError: Unexpected templating type error occurred on ({% for i in range(num) %}\n{{ i }}\n{% endfor %}\n): an integer is required"}
	to retry, use: --limit @/home/ubuntu/vtp/ansible/foo.retry
</code></pre></div>
<p dir="auto">That is, in the with_items case, the value is string "5" rather than number 5.</p>
<h5 dir="auto">WORKAROUND</h5>
<p dir="auto">Change the template so it says:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{% for i in range(num | int) %}
{{ i }}
{% endfor %}"><pre class="notranslate"><code class="notranslate">{% for i in range(num | int) %}
{{ i }}
{% endfor %}
</code></pre></div>
<p dir="auto">But this seems very arbitrary. Surely an integer value is always an integer value?</p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/my2ndhead/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/my2ndhead">@my2ndhead</a> on 2016-02-08T19:49:03Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">ini_file module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">2.0.0.2</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Compared to 1.9.x the version 2.0.0.2 does not add an empty line between sections. This makes ini-files hard to read.</p>
<p dir="auto">1.9.x</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[section1]
key=value

[section2]
key=value"><pre class="notranslate"><code class="notranslate">[section1]
key=value

[section2]
key=value
</code></pre></div>
<p dir="auto">2.0.0.2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[section1]
key=value
[section2]
key=value"><pre class="notranslate"><code class="notranslate">[section1]
key=value
[section2]
key=value
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="132239837" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/2988" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2988/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/2988">ansible/ansible-modules-core#2988</a></p>