<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">ansible 2.1.0.0</p>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">Using <a href="https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack">https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack</a></p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Centos 7</p>
<h5 dir="auto">SUMMARY &amp; STEPS TO REPRODUCE</h5>
<p dir="auto">I'm testing with this repo <a href="https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack">https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack</a></p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">Deployment of Openstack</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed: [controller] (item={u'vhost': u'/', u'password': u'Uawaiyiz6tee7chietoC', u'user': u'openstack-glance'}) =&gt; 
{&quot;failed&quot;: true, &quot;item&quot;: {&quot;password&quot;: &quot;Uawaiyiz6tee7chietoC&quot;, &quot;user&quot;: &quot;openstack-glance&quot;, &quot;vhost&quot;: &quot;/&quot;}, 
&quot;module_stderr&quot;: &quot;&quot;, &quot;module_stdout&quot;: &quot;Traceback (most recent call last):\r\n  
File \&quot;/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\&quot;, line 302, in &lt;module&gt;\r\n    main()\r\n  
File \&quot;/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\&quot;, line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \&quot;/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\&quot;, line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \&quot;/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\&quot;, line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  
File \&quot;/tmp/ansible_otGN8Y/ansible_modlib.zip/ansible/module_utils/basic.py\&quot;, line 1993, in run_command\r\n  
File \&quot;/usr/lib/python2.7/posixpath.py\&quot;, line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;, &quot;parsed&quot;: false}"><pre class="notranslate"><code class="notranslate">failed: [controller] (item={u'vhost': u'/', u'password': u'Uawaiyiz6tee7chietoC', u'user': u'openstack-glance'}) =&gt; 
{"failed": true, "item": {"password": "Uawaiyiz6tee7chietoC", "user": "openstack-glance", "vhost": "/"}, 
"module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  
File \"/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\", line 302, in &lt;module&gt;\r\n    main()\r\n  
File \"/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\", line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \"/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\", line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \"/tmp/ansible_otGN8Y/ansible_module_rabbitmq_user.py\", line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  
File \"/tmp/ansible_otGN8Y/ansible_modlib.zip/ansible/module_utils/basic.py\", line 1993, in run_command\r\n  
File \"/usr/lib/python2.7/posixpath.py\", line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n", "msg": "MODULE FAILURE", "parsed": false}
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed: [controller] (item={u'vhost': u'/', u'password': u'Zuu1aabaewoh5tei2agh', u'user': u'openstack-nova'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;password&quot;: &quot;Zuu1aabaewoh5tei2agh&quot;, &quot;user&quot;: &quot;openstack-nova&quot;, &quot;vhost&quot;: &quot;/&quot;}, &quot;module_stderr&quot;: &quot;&quot;, &quot;module_stdout&quot;: &quot;Traceback (most recent call last):\r\n  
File \&quot;/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\&quot;, line 302, in &lt;module&gt;\r\n    main()\r\n  
File \&quot;/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\&quot;, line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \&quot;/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\&quot;, line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \&quot;/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\&quot;, line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  
File \&quot;/tmp/ansible_tpcgZ7/ansible_modlib.zip/ansible/module_utils/basic.py\&quot;, line 1993, in run_command\r\n  
File \&quot;/usr/lib/python2.7/posixpath.py\&quot;, line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;, &quot;parsed&quot;: false}"><pre class="notranslate"><code class="notranslate">failed: [controller] (item={u'vhost': u'/', u'password': u'Zuu1aabaewoh5tei2agh', u'user': u'openstack-nova'}) =&gt; {"failed": true, "item": {"password": "Zuu1aabaewoh5tei2agh", "user": "openstack-nova", "vhost": "/"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  
File \"/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\", line 302, in &lt;module&gt;\r\n    main()\r\n  
File \"/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\", line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \"/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\", line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \"/tmp/ansible_tpcgZ7/ansible_module_rabbitmq_user.py\", line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  
File \"/tmp/ansible_tpcgZ7/ansible_modlib.zip/ansible/module_utils/basic.py\", line 1993, in run_command\r\n  
File \"/usr/lib/python2.7/posixpath.py\", line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n", "msg": "MODULE FAILURE", "parsed": false}
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failed: [controller] (item={u'vhost': u'/', u'password': u'seiye6Ekah1hoxeshook', u'user': u'openstack-neutron'}) =&gt; {&quot;failed&quot;: true, &quot;item&quot;: {&quot;password&quot;: &quot;seiye6Ekah1hoxeshook&quot;, &quot;user&quot;: &quot;openstack-neutron&quot;, &quot;vhost&quot;: &quot;/&quot;}, &quot;module_stderr&quot;: &quot;&quot;, &quot;module_stdout&quot;: &quot;Traceback (most recent call last):\r\n  
File \&quot;/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\&quot;, line 302, in &lt;module&gt;\r\n    main()\r\n  
File \&quot;/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\&quot;, line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \&quot;/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\&quot;, line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \&quot;/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\&quot;, line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  File \&quot;/tmp/ansible_8isjDu/ansible_modlib.zip/ansible/module_utils/basic.py\&quot;, line 1993, in run_command\r\n  File \&quot;/usr/lib/python2.7/posixpath.py\&quot;, line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n&quot;, &quot;msg&quot;: &quot;MODULE FAILURE&quot;, &quot;parsed&quot;: false}"><pre class="notranslate"><code class="notranslate">failed: [controller] (item={u'vhost': u'/', u'password': u'seiye6Ekah1hoxeshook', u'user': u'openstack-neutron'}) =&gt; {"failed": true, "item": {"password": "seiye6Ekah1hoxeshook", "user": "openstack-neutron", "vhost": "/"}, "module_stderr": "", "module_stdout": "Traceback (most recent call last):\r\n  
File \"/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\", line 302, in &lt;module&gt;\r\n    main()\r\n  
File \"/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\", line 274, in main\r\n    if rabbitmq_user.get():\r\n  
File \"/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\", line 155, in get\r\n    users = self._exec(['list_users'], True)\r\n  
File \"/tmp/ansible_8isjDu/ansible_module_rabbitmq_user.py\", line 150, in _exec\r\n    rc, out, err = self.module.run_command(cmd + args, check_rc=True)\r\n  File \"/tmp/ansible_8isjDu/ansible_modlib.zip/ansible/module_utils/basic.py\", line 1993, in run_command\r\n  File \"/usr/lib/python2.7/posixpath.py\", line 261, in expanduser\r\n    if not path.startswith('~'):\r\nAttributeError: 'list' object has no attribute 'startswith'\r\n", "msg": "MODULE FAILURE", "parsed": 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">module</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.0
  config file = None
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = ~/Projects/python/playbooks/env/lib/python3.5/site-packages/ansible
  executable location = ~/Projects/python/playbooks/env/bin/ansible
  python version = 3.5.3 (default, Apr 23 2017, 18:09:27) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]"><pre class="notranslate"><code class="notranslate">ansible 2.4.0
  config file = None
  configured module search path = ['~/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = ~/Projects/python/playbooks/env/lib/python3.5/site-packages/ansible
  executable location = ~/Projects/python/playbooks/env/bin/ansible
  python version = 3.5.3 (default, Apr 23 2017, 18:09:27) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">When using <code class="notranslate">include_role</code> inside a file loaded by <code class="notranslate">include_tasks</code>, the role is played once per host instead of being run only once. The result is that all tasks from this roles are played twice or more for each hosts.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto"><a href="https://github.com/ansible/ansible/files/1134997/playground.zip">playground.zip</a></p>
<p dir="auto">Unzip the attached archive which contains an inventory:</p>
<p dir="auto">hosts</p>
<div class="highlight highlight-source-ini notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="server-1
server-2"><pre class="notranslate">server-1
server-2</pre></div>
<p dir="auto">recipe.yml:</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- hosts: all
  remote_user: root
  name: Include Tests
  roles:
    - role: foo"><pre class="notranslate">- <span class="pl-ent">hosts</span>: <span class="pl-s">all</span>
  <span class="pl-ent">remote_user</span>: <span class="pl-s">root</span>
  <span class="pl-ent">name</span>: <span class="pl-s">Include Tests</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-ent">role</span>: <span class="pl-s">foo</span></pre></div>
<p dir="auto">2 roles:</p>
<ul dir="auto">
<li>foo</li>
</ul>
<p dir="auto">roles/foo/tasks/main.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- include_tasks: foo.yml"><pre class="notranslate">- <span class="pl-ent">include_tasks</span>: <span class="pl-s">foo.yml</span></pre></div>
<p dir="auto">roles/foo/tasks/foo.yml</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- include_role:
    name: bar"><pre class="notranslate">- <span class="pl-ent">include_role</span>:
    <span class="pl-ent">name</span>: <span class="pl-s">bar</span></pre></div>
<ul dir="auto">
<li>bar<br>
roles/bar/tasks/main.yml</li>
</ul>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="- debug: msg=&quot;Hello from Bar&quot;"><pre class="notranslate">- <span class="pl-ent">debug</span>: <span class="pl-s">msg="Hello from Bar"</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">bar tasks are run once for each host, just like it behave when using import_tasks instead of include_tasks</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Include Tests] *****************************************************************

TASK [Gathering Facts] ***************************************************************
ok: [server-1]
ok: [server-2]

TASK [foo : include_tasks] ***********************************************************
included: /Users/jddupas/Projects/python/playbooks/playground/roles/foo/tasks/foo.yml for server-1, server-2

TASK [foo : include_role] ************************************************************

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}
ok: [server-2] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}

PLAY RECAP ***************************************************************************
server-1                   : ok=4    changed=0    unreachable=0    failed=0   
server-2                   : ok=4    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [Include Tests] *****************************************************************

TASK [Gathering Facts] ***************************************************************
ok: [server-1]
ok: [server-2]

TASK [foo : include_tasks] ***********************************************************
included: /Users/jddupas/Projects/python/playbooks/playground/roles/foo/tasks/foo.yml for server-1, server-2

TASK [foo : include_role] ************************************************************

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}
ok: [server-2] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}

PLAY RECAP ***************************************************************************
server-1                   : ok=4    changed=0    unreachable=0    failed=0   
server-2                   : ok=4    changed=0    unreachable=0    failed=0
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">bar tasks are run twice for each host.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="PLAY [Include Tests] *****************************************************************

TASK [Gathering Facts] ***************************************************************
ok: [server-1]
ok: [server-2]

TASK [foo : include_tasks] ***********************************************************
included: /Users/jddupas/Projects/python/playbooks/playground/roles/foo/tasks/foo.yml for server-1, server-2

TASK [foo : include_role] ************************************************************

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}
ok: [server-2] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}
ok: [server-2] =&gt; {
    &quot;failed&quot;: false,
    &quot;msg&quot;: &quot;Hello from Bar&quot;
}

PLAY RECAP ***************************************************************************
server-1                   : ok=4    changed=0    unreachable=0    failed=0   
server-2                   : ok=4    changed=0    unreachable=0    failed=0"><pre class="notranslate"><code class="notranslate">PLAY [Include Tests] *****************************************************************

TASK [Gathering Facts] ***************************************************************
ok: [server-1]
ok: [server-2]

TASK [foo : include_tasks] ***********************************************************
included: /Users/jddupas/Projects/python/playbooks/playground/roles/foo/tasks/foo.yml for server-1, server-2

TASK [foo : include_role] ************************************************************

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}
ok: [server-2] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}

TASK [bar : debug] *******************************************************************
ok: [server-1] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}
ok: [server-2] =&gt; {
    "failed": false,
    "msg": "Hello from Bar"
}

PLAY RECAP ***************************************************************************
server-1                   : ok=4    changed=0    unreachable=0    failed=0   
server-2                   : ok=4    changed=0    unreachable=0    failed=0
</code></pre></div>