become: True is not inherited in role includes below 1 level #20129

Closed
profhase opened this Issue Jan 11, 2017 · 1 comment

Projects

None yet

3 participants

@profhase
profhase commented Jan 11, 2017 edited
ISSUE TYPE
  • Bug Report
COMPONENT NAME

become

ANSIBLE VERSION
2.2.0.0
OS / ENVIRONMENT

ubuntu 16.04

SUMMARY

Become is not inherited if there is more than one level of inclusion in role. Here the example tree from the ansible root:

├── roles
│   └── test-includes
│       └── tasks
│           ├── includes
│           │   ├── foo.yml
│           │   └── subincludes
│           │       └── baz.yml
│           └── main.yml
└── test_include.yml
  • The test_include.yml uses the role test_includes,
  • In the role, main.yml includes includes/foo.yml with become: True
  • the foo.yml includes subincludes/baz.yml

The tasks in includes/foo.yml have become: True
The tasks in includes/subincludes/baz.yml have become: False

STEPS TO REPRODUCE

Build the directory as described above. The files have the following content

# test_include.yml
- hosts: localhost
  roles:
    - "test-includes"
####################################

# roles/test-includes/main.yml
- include: includes/foo.yml
  become: True

####################################

# roles/test-includes/includes/foo.yml
- shell:
    cat /etc/shadow

- include: subincludes/baz.yml

###############################

# roles/sub-includes/baz.yml
- shell:
    cat /etc/shadow

################################
EXPECTED RESULTS

seemless run

ACTUAL RESULTS

In subincludes the /etc/shadow cannot be read, while it can be read in includes


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

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

TASK [test-includes : command] *************************************************
changed: [localhost]

TASK [test-includes : command] *************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "cat /etc/shadow", "delta": "0:00:00.001779", "end": "2017-
01-11 13:20:32.272565", "failed": true, "rc": 1, "start": "2017-01-11 13:20:32.270786", "stderr": "cat: /etc/shadow
: Permission denied", "stdout": "", "stdout_lines": [], "warnings": []}                                           
        to retry, use: --limit @/home/me/my/ansible-test/test_include.retry

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1   
@nitzmahone
Member

I was able to repro this on 2.2.0, but has already been fixed in devel and the current 2.2.1rc.

@nitzmahone nitzmahone closed this Jan 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment