Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION

ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.14 (default, Jan 17 2018, 14:28:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)

CONFIGURATION

$ ansible-config dump --only-changed
(no output)

OS / ENVIRONMENT

N/A

SUMMARY

handlers in roles that have been loaded using include_role are not executed when used in the "conventional" way. Using listen works, though.

STEPS TO REPRODUCE

#!/bin/bash
tmp=$(mktemp -d)
cd "${tmp}"
tee ansible.cfg <<EOF
[defaults]
nocows = 1
force_handlers = True
EOF
mkdir -p roles/role_{import,include{,_works}}/{tasks,handlers}
tee roles/role_{import,include}/handlers/main.yml <<EOF
---
- name: "my handler"
debug: msg="running handler in {{role_name}}"
EOF
tee roles/role_{import,include{,_works}}/tasks/main.yml <<EOF
---
- name: "do something"
command: /bin/true
notify: my handler
EOF
tee roles/role_include_works/handlers/main.yml <<EOF
---
- name: "my handler"
listen: ['my handler']
debug: msg="running handler in {{role_name}}"
EOF
tee run.yml <<EOF
---
- hosts: localhost
gather_facts: no
tasks:
- import_role: name=role_import
- include_role: name=role_include
- include_role: name=role_include_works
EOF
ansible-playbook run.yml

EXPECTED RESULTS

TASK [role_import : do something] *****************************************************************
changed: [localhost]

TASK [include_role] *******************************************************************************

TASK [role_include : do something] ****************************************************************
changed: [localhost]

TASK [include_role] *******************************************************************************

TASK [role_include_works : do something] **********************************************************
changed: [localhost]

RUNNING HANDLER [role_import : my handler] ********************************************************
ok: [localhost] => {
"msg": "running handler in role_import"
}

RUNNING HANDLER [role_include : my handler] ********************************************************
ok: [localhost] => {
"msg": "running handler in role_include"
}

RUNNING HANDLER [role_include_works : my handler] *************************************************
ok: [localhost] => {
"msg": "running handler in role_include_works"
}

PLAY RECAP ****************************************************************************************
localhost : ok=5 changed=3 unreachable=0 failed=0

ACTUAL RESULTS

PLAY [localhost] **********************************************************************************

TASK [role_import : do something] *****************************************************************
changed: [localhost]

TASK [include_role] *******************************************************************************

TASK [role_include : do something] ****************************************************************
changed: [localhost]

TASK [include_role] *******************************************************************************

TASK [role_include_works : do something] **********************************************************
changed: [localhost]

RUNNING HANDLER [role_import : my handler] ********************************************************
ok: [localhost] => {
"msg": "running handler in role_import"
}

RUNNING HANDLER [role_include_works : my handler] *************************************************
ok: [localhost] => {
"msg": "running handler in role_include_works"
}

PLAY RECAP ****************************************************************************************
localhost : ok=5 changed=3 unreachable=0 failed=0

Issue 2:
Issue Type:

Bug report.

Ansible Version:

1.5.5

Environment:

Workstation: Archlinux

Managed host(s): CentOS 6.5, Ubuntu 12.04, Archlinux, ...

Summary:

Follow up for #6443 and #6499.

Using git module with

sudo: yes

sudo_user: some_user

results in Python os.stat error when ansible_ssh_user remote hosts

$HOME directory was created with umask 0077 resulting in 0700 directory

permissions of /home/ansible_ssh_user.

Cloning a repository using SSH or HTTP as transport layer. Connecting

to the managed node with -c local or SSH.

Steps To Reproduce:

$ ansible-playbook -c local -vvvv /path/to/playbook.yml

---
- hosts: localhost
sudo: yes
sudo_user: root
vars:
- git_user_name: foobar
- git_user_home: /tmp/{{ git_user_name }}
- git_clone_repo: https://github.com/ansible/ansible
tasks:
- name: Ensure ansible_ssh_user home directory permissions
file:
state=directory
mode=0700
dest={{ ansible_env['PWD'] }}

- name: Create Git user
user:
name={{ git_user_name }}
home={{ git_user_home }}
shell=/bin/bash

- name: Clone Git repository
sudo: yes
sudo_user: "{{ git_user_name }}"
git:
repo={{ git_clone_repo }}
dest={{ git_user_home }}/clone_me_some_repo_for_great_good
force=yes
remote=origin

Cleaning up:

$ sudo userdel --remove foobar
$ sudo rm -rf /tmp/foobar

Expected Results:

$ sudo -i
$ [ -d /tmp/foobar/clone_me_some_repo_for_great_good/.git ]
$ echo $?
0

Actual Results:

ANSIBLE_NOCOWS=1 ansible-playbook -c local -vvvv /tmp/github-bug-report/playbook.yml

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
<localhost> REMOTE_MODULE setup
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826 && chmod a+rx /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826 && echo /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826']
<localhost> PUT /tmp/tmpUyGh5T TO /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826/setup
<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=smqkhnaznohkkoqjrgsrlghissfvtnau] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-smqkhnaznohkkoqjrgsrlghissfvtnau; /usr/bin/python2 /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826/setup; rm -rf /tmp/ansible/ssh_user/ansible-tmp-1398244809.55-224144278976826/ >/dev/null 2>&1'"'"''
ok: [localhost]

TASK: [Ensure ansible_ssh_user home directory permissions] ********************
<localhost> REMOTE_MODULE file state=directory mode=0700 dest=/home/ssh_user
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477 && chmod a+rx /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477 && echo /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477']
<localhost> PUT /tmp/tmpiyGv99 TO /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477/file
<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=dpmuynuqcjjmfyvfumzbeldutfblhhsq] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-dpmuynuqcjjmfyvfumzbeldutfblhhsq; /usr/bin/python2 /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477/file; rm -rf /tmp/ansible/ssh_user/ansible-tmp-1398244809.76-13206589431477/ >/dev/null 2>&1'"'"''
ok: [localhost] => {"changed": false, "gid": 100, "group": "users", "mode": "0700", "owner": "ssh_user", "path": "/home/ssh_user", "size": 956, "state": "directory", "uid": 1042}

TASK: [Create Git user] *******************************************************
<localhost> REMOTE_MODULE user name=foobar home=/tmp/foobar shell=/bin/bash
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750 && chmod a+rx /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750 && echo /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750']
<localhost> PUT /tmp/tmpdiz_cO TO /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750/user
<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=lwvqzyalydhiquyjktyqonjclueegsut] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-lwvqzyalydhiquyjktyqonjclueegsut; /usr/bin/python2 /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750/user; rm -rf /tmp/ansible/ssh_user/ansible-tmp-1398244809.83-38414991496750/ >/dev/null 2>&1'"'"''
ok: [localhost] => {"append": false, "changed": false, "comment": "", "group": 1043, "home": "/tmp/foobar", "move_home": false, "name": "foobar", "shell": "/bin/bash", "state": "present", "uid": 1043}

TASK: [Clone Git repository] **************************************************
<localhost> REMOTE_MODULE git repo=https://github.com/ansible/ansible dest=/tmp/foobar/clone_me_some_repo_for_great_good force=yes remote=origin
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p /tmp/ansible-tmp-1398244809.91-40810594643527 && chmod a+rx /tmp/ansible-tmp-1398244809.91-40810594643527 && echo /tmp/ansible-tmp-1398244809.91-40810594643527']
<localhost> PUT /tmp/tmpV7Dqnb TO /tmp/ansible-tmp-1398244809.91-40810594643527/git
<localhost> EXEC ['/bin/sh', '-c', 'chmod a+r /tmp/ansible-tmp-1398244809.91-40810594643527/git']
<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=uofualorxsuihhxfftcbklsehewekjop] password: " -u foobar /bin/sh -c '"'"'echo SUDO-SUCCESS-uofualorxsuihhxfftcbklsehewekjop; /usr/bin/python2 /tmp/ansible-tmp-1398244809.91-40810594643527/git'"'"''
<localhost> EXEC ['/bin/sh', '-c', 'rm -rf /tmp/ansible-tmp-1398244809.91-40810594643527/ >/dev/null 2>&1']
failed: [localhost] => {"cmd": ["/usr/bin/git", "ls-remote", "https://github.com/ansible/ansible", "-h", "refs/heads/HEAD"], "failed": true, "rc": 128}
stderr: fatal: failed to stat '.': Permission denied

msg: fatal: failed to stat '.': Permission denied

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/home/ssh_user/playbook.retry

localhost : ok=3 changed=0 unreachable=0 failed=1

[1] 6514 exit 2 ANSIBLE_NOCOWS=1 ansible-playbook -c local -vvvv