Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong search paths with include_role #34782

Closed
torgiren opened this issue Jan 12, 2018 · 3 comments
Closed

Wrong search paths with include_role #34782

torgiren opened this issue Jan 12, 2018 · 3 comments
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@torgiren
Copy link

ISSUE TYPE
  • Bug Report (propably)
COMPONENT NAME

dynamic includes

ANSIBLE VERSION
ansible 2.5.0 (devel e3b5be0887) last updated 2018/01/12 07:53:31 (GMT +200)
  config file = None
  configured module search path = [u'/home/torgiren/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /tmp/ansible/lib/ansible
  executable location = /tmp/ansible/bin/ansible
  python version = 2.7.14 (default, Nov 26 2017, 14:35:36) [GCC 5.4.0]

same on 2.4.0

CONFIGURATION

default configuration
ansible-config dump --only-changed - empty result

OS / ENVIRONMENT

Linux, but it isn't important

SUMMARY

include path are wrong, then using include_roles.
Ansible does not search for tasks in role that use include_tasks.
When we use include_role, the search path is limited only to parent roles.
In the example below, we have roles:
top - which include_role role one
one - which include_role role two
two - which dependency role three
three - which include_task file in her tasks/

when using include_role, included_tasks are search only in one/tasks and two/tasks.
It's bug in my opinion, because it should search in three/tasks as well. (and maybe in top/tasks?)

STEPS TO REPRODUCE

roles/top/tasks/main.yml

- include_role:
    name: one

roles/one/tasks/main.yml

- debug:
    msg: "one"

- include_role:
    name: two

roles/two/tasks/main.yml

- debug:
    msg: "two"

roles/two/meta/main.yml

dependencies:
- three

roles/three/tasks/main.yml

- debug:
    msg: "three"

- include_tasks: my.yml

roles/three/tasks/my.yml

- debug:
    msg: "it my"

playbook_a.yml

- hosts:
    localhost
  roles:
  - three

playbook_b.yml

- hosts:
    localhost
  roles:
  - top
EXPECTED RESULTS
ansible-playbook -i inventory playbook_a.yml                           

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

TASK [Gathering Facts] ***********************************************************************
ok: [localhost]

TASK [three : debug] *************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "three"
}

TASK [three : include_tasks] *****************************************************************
included: /tmp/uuy/roles/three/tasks/my.yml for localhost

TASK [three : debug] *************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "it my"
}

PLAY RECAP ***********************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0   

ansible-playbook -i inventory playbook_b.yml

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

TASK [Gathering Facts] ***********************************************************************
ok: [localhost]

TASK [top : include_role] ********************************************************************

TASK [one : debug] ***************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "one"
}

TASK [one : include_role] ********************************************************************

TASK [three : debug] *************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "three"
}

TASK [three : include_tasks] *****************************************************************
included: /tmp/uuy/roles/three/tasks/my.yml for localhost

TASK [three : debug] *************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "it my"
}

TASK [two : debug] ***************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "two"
}

PLAY RECAP ***********************************************************************************
localhost                  : ok=6    changed=0    unreachable=0    failed=0   
ACTUAL RESULTS
 ansible-playbook -i inventory playbook_a.yml

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

TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]

TASK [three : debug] **************************************************************************************************************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "three"
}

TASK [three : include_tasks] ******************************************************************************************************************************************************************
included: /tmp/uuy/roles/three/tasks/my.yml for localhost

TASK [three : debug] **************************************************************************************************************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "it my"
}

PLAY RECAP ************************************************************************************************************************************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0   

 ansible-playbook -i inventory playbook_b.yml

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

TASK [Gathering Facts] ************************************************************************************************************************************************************************
ok: [localhost]

TASK [top : include_role] *********************************************************************************************************************************************************************

TASK [one : debug] ****************************************************************************************************************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "one"
}

TASK [one : include_role] *********************************************************************************************************************************************************************

TASK [three : debug] **************************************************************************************************************************************************************************
ok: [localhost] => {
    "attempts": 1, 
    "msg": "three"
}

TASK [three : include_tasks] ******************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"reason": "Unable to retrieve file contents\nCould not find or access '/tmp/uuy/my.yml'"}
        to retry, use: --limit @/tmp/uuy/playbook_b.retry

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

and with strace, we can see:

strace -f -e file ansible-playbook -i inventory playbook_b.yml 2>&1|grep my.yml 
[pid 19037] stat("/tmp/uuy/roles/two/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/two/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/two/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/two/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/my.yml", 0x7fff64d17930) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/one/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/one/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/one/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/roles/one/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/tasks/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/my.yml", 0x7fff64d17730) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/my.yml", 0x7fff64d17930) = -1 ENOENT (No such file or directory)
[pid 19037] stat("/tmp/uuy/my.yml", 0x7fff64d17330) = -1 ENOENT (No such file or directory)
fatal: [localhost]: FAILED! => {"reason": "Unable to retrieve file contents\nCould not find or access '/tmp/uuy/my.yml'"}

torgiren added a commit to torgiren/ansible that referenced this issue Jan 12, 2018
@ansibot
Copy link
Contributor

ansibot commented Jan 12, 2018

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jan 12, 2018
@mkrizek
Copy link
Contributor

mkrizek commented Jan 12, 2018

cc @bcoca

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Jan 12, 2018
@torgiren
Copy link
Author

look like it's fixed

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants