title: Ansible multiple include with multiple tasks?
body: <p>I have an Ansible playbook that includes a file twice and passes in a parameter to change the behavior:</p>
  
  <p><strong>site.yml:</strong></p>
  
  <pre><code>---
  - tasks:
    - include: test.yml parm=AAA
    - include: test.yml parm=BBB
  </code></pre>
  
  <p>The include file just prints the parameter value:</p>
  
  <p><strong>test.yml:</strong></p>
  
  <pre><code>- debug: msg="dbg 1 {{ parm }}"
  </code></pre>
  
  <p>The inventory file is set to run on localhost:</p>
  
  <p><strong>inventory:</strong></p>
  
  <pre><code>localhost ansible_connection=local
  </code></pre>
  
  <p>The result is what I expect, the include file runs twice, once with parm=AAA and once with parm=BBB:</p>
  
  <pre><code>&gt;ansible-playbook -i inventory site.yml
  
  PLAY ***************************************************************************
  
  TASK [setup] *******************************************************************
  ok: [localhost]
  
  TASK [include parm=AAA] ********************************************************
  included: test.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 AAA"
  }
  
  TASK [include parm=BBB] ********************************************************
  included: test.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 BBB"
  }
  
  PLAY RECAP *********************************************************************
  localhost                  : ok=5    changed=0    unreachable=0    failed=0   
  </code></pre>
  
  <p>Great. Now I need to do a second task in the include file:</p>
  
  <p><strong>test.yml:</strong></p>
  
  <pre><code>- debug: msg="dbg 1 {{ parm }}"
  - debug: msg="dbg 2 {{ parm }}"
  </code></pre>
  
  <p>What I expect is that the include file will be executed twice, just as before, first doing the original 'dbg 1 AAA' task and then the new 'dbg 2 AAA' task, and then second doing the original 'dbg 1 BBB' task and then the new 'dbg 2 BBB' task.</p>
  
  <p>It does this instead:</p>
  
  <pre><code>&gt;ansible-playbook -i inventory site.yml
  
  PLAY ***************************************************************************
  
  TASK [setup] *******************************************************************
  ok: [localhost]
  
  TASK [include parm=AAA] ********************************************************
  included: test.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 AAA"
  }
  
  TASK [debug msg=dbg 2 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 2 AAA"
  }
  
  PLAY RECAP *********************************************************************
  localhost                  : ok=4    changed=0    unreachable=0    failed=0   
  </code></pre>
  
  <p>It has skipped the second include. I thought that perhaps there was a problem including the same file multiple times, so I duplicated the include file with a new name:</p>
  
  <p><strong>test2.yml:</strong></p>
  
  <pre><code>- debug: msg="dbg 1 {{ parm }}"
  - debug: msg="dbg 2 {{ parm }}"
  </code></pre>
  
  <p>And adjust the playbook to include that instead:</p>
  
  <p><strong>site.yml:</strong></p>
  
  <pre><code>---
  - tasks:
    - include: test.yml parm=AAA
    - include: test2.yml parm=BBB
  </code></pre>
  
  <p>Then if test.yml has only one task, I get the expected result:</p>
  
  <pre><code>PLAY ***************************************************************************
  
  TASK [setup] *******************************************************************
  ok: [localhost]
  
  TASK [include parm=AAA] ********************************************************
  included: test.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 AAA"
  }
  
  TASK [include parm=BBB] ********************************************************
  included: test2.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 BBB"
  }
  
  TASK [debug msg=dbg 2 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 2 BBB"
  }
  
  PLAY RECAP *********************************************************************
  localhost                  : ok=6    changed=0    unreachable=0    failed=0   
  </code></pre>
  
  <p>But if test.yml has two tasks, it skips the second include:</p>
  
  <pre><code>PLAY ***************************************************************************
  
  TASK [setup] *******************************************************************
  ok: [localhost]
  
  TASK [include parm=AAA] ********************************************************
  included: test.yml for localhost
  
  TASK [debug msg=dbg 1 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 1 AAA"
  }
  
  TASK [debug msg=dbg 2 {{ parm }}] **********************************************
  ok: [localhost] =&gt; {
      "changed": false, 
      "msg": "dbg 2 AAA"
  }
  
  PLAY RECAP *********************************************************************
  localhost                  : ok=4    changed=0    unreachable=0    failed=0   
  </code></pre>
  
  <p>What am I missing? There are no errors or failures, and the two lines in the include file are nearly identical. Why does having more than one line in the first include file cause the second include to be skipped?</p>
  
  <p>If I add more debug lines to the playbook:</p>
  
  <p><strong>site.yml:</strong></p>
  
  <pre><code>---
  - tasks:
    - include: test.yml parm=AAA
    - debug: msg="1"
    - include: test2.yml parm=BBB
    - debug: msg="2"
    - debug: msg="3"
  </code></pre>
  
  <p>The debug messages are output only if the include file that preceeds them have exactly one line.</p>
  
  <p>I am running Ansible from git://github.com/ansible/ansible.git devel branch, updated immediately before testing this.</p>