Issue 1:
ISSUE TYPE

Bug Report

ANSIBLE VERSION

ansible 2.1.0.0

CONFIGURATION

Using https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack

OS / ENVIRONMENT

Centos 7

SUMMARY & STEPS TO REPRODUCE

I'm testing with this repo https://github.com/openstack-ansible-galaxy/vagrant-ansible-openstack

EXPECTED RESULTS

Deployment of Openstack

ACTUAL RESULTS

failed: [controller] (item={u'vhost': u'/', u'password': u'Uawaiyiz6tee7chietoC', u'user': u'openstack-glance'}) =>
{"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 <module>\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}

failed: [controller] (item={u'vhost': u'/', u'password': u'Zuu1aabaewoh5tei2agh', u'user': u'openstack-nova'}) => {"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 <module>\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}

failed: [controller] (item={u'vhost': u'/', u'password': u'seiye6Ekah1hoxeshook', u'user': u'openstack-neutron'}) => {"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 <module>\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}

Issue 2:
ISSUE TYPE

Bug Report

COMPONENT NAME

module

ANSIBLE VERSION

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)]

CONFIGURATION

N/A

OS / ENVIRONMENT

N/A

SUMMARY

When using include_role inside a file loaded by include_tasks, 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.

STEPS TO REPRODUCE

playground.zip

Unzip the attached archive which contains an inventory:

hosts

server-1
server-2

recipe.yml:

- hosts: all
remote_user: root
name: Include Tests
roles:
- role: foo

2 roles:

foo

roles/foo/tasks/main.yml

- include_tasks: foo.yml

roles/foo/tasks/foo.yml

- include_role:
name: bar

bar

roles/bar/tasks/main.yml

- debug: msg="Hello from Bar"

EXPECTED RESULTS

bar tasks are run once for each host, just like it behave when using import_tasks instead of include_tasks

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] => {
"failed": false,
"msg": "Hello from Bar"
}
ok: [server-2] => {
"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

ACTUAL RESULTS

bar tasks are run twice for each host.

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] => {
"failed": false,
"msg": "Hello from Bar"
}
ok: [server-2] => {
"failed": false,
"msg": "Hello from Bar"
}

TASK [bar : debug] *******************************************************************
ok: [server-1] => {
"failed": false,
"msg": "Hello from Bar"
}
ok: [server-2] => {
"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