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

include_role and meta dependencies: strange behaviour on conditionals #23733

Closed
philfry opened this issue Apr 19, 2017 · 7 comments
Closed

include_role and meta dependencies: strange behaviour on conditionals #23733

philfry opened this issue Apr 19, 2017 · 7 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. include_role support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@philfry
Copy link
Contributor

philfry commented Apr 19, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

role dependencies

ANSIBLE VERSION
ansible 2.3.0.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jan 12 2017, 17:59:37) [GCC 6.3.1 20161221 (Red Hat 6.3.1-1)]
CONFIGURATION

n/a

OS / ENVIRONMENT

n/a

SUMMARY

an include_role gets skipped when a former dependency condition is not met

STEPS TO REPRODUCE
echo -e "[defaults]\ninventory = ./inventory\nnocows = 1" > ansible.cfg
echo "localhost ansible_connection=local" > inventory
mkdir -p roles/{dep{1..3},master}/{files,templates,defaults,meta,handlers,vars,tasks}
echo -e "---\n- debug: msg='in {{role_name}}'" | tee roles/dep{1..3}/tasks/main.yml > /dev/null
echo -e "---\ndependencies:\n  - role: dep1\n  - role: dep2\n    when: false" > roles/master/meta/main.yml              
echo -e "---\n- include_role: name=dep3"  > roles/master/tasks/main.yml
echo -e "---\n- hosts: [ 'localhost' ]\n  gather_facts: no\n  roles: [ 'master' ]" > bug.yml
ansible-playbook bug.yml
EXPECTED RESULTS
ok: [localhost] => {
    "changed": false, 
    "msg": "in dep1"
}
ok: [localhost] => {
    "changed": false, 
    "msg": "in dep3"
}
ACTUAL RESULTS
ok: [localhost] => {
    "changed": false, 
    "msg": "in dep1"
}

verbose output in gist: https://gist.github.com/philfry/8099cc98e12d7b36bf015dd856b2c3cb

@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bug_report needs_triage Needs a first human triage before being processed. labels Apr 19, 2017
@snowsky
Copy link
Contributor

snowsky commented Apr 19, 2017

I like the command lines which is easy to reproduce the issue.

@snowsky
Copy link
Contributor

snowsky commented Apr 19, 2017

no idea why dep3 is lost

@snowsky
Copy link
Contributor

snowsky commented Apr 19, 2017

The issue is caused by when cause.

@eerorika
Copy link

It seems to me that this could be the same bug I reported earlier on 2.2: #23379

@abadger abadger removed the needs_triage Needs a first human triage before being processed. label Apr 20, 2017
@alikins
Copy link
Contributor

alikins commented Apr 20, 2017

(repro expanded for reference)

ansible.cfg

[defaults]\ninventory = ./inventory
nocows = 1

bug.yml

---
- hosts: [ 'localhost' ]
  gather_facts: no
  roles: [ 'master' ]

roles/master/meta/main.yml

---
dependencies:
  - role: dep1
  - role: dep2
    when: false

roles/master/tasks/main.yml

---
- include_role: name=dep3

roles/dep*/tasks/main.yml

---
- debug: msg='in {{role_name}}'

@philfry
Copy link
Contributor Author

philfry commented Apr 21, 2017

The bug only occurs when using include_role in a role.
This example works fine:

  • roles/master/tasks/main.yml
---
- debug: msg="in master"
  • bug.yml
---
- hosts: [ 'localhost' ]
  gather_facts: no
  roles: [ 'master' ]
  tasks:
    - include_role: name=dep3

results

TASK [dep1 : task dep1]
ok: [localhost] => {
    "msg": "in dep1"
}

TASK [dep2 : task dep2]
skipping: [localhost]

TASK [master : task master]
ok: [localhost] => {
    "msg": "in master"
}

TASK [dep3 : task dep3]
ok: [localhost] => {
    "msg": "in dep3"
}

While playing around with ansible's source code and adding some debug lines I found the following:

playbook/role/__init__.py:_load_dependencies
  -> playbook/role/__init__.py:load
    -> playbook/role/__init__.py:_load_role_data
       -> playbook/helpers.py:load_list_of_blocks
          found TASK: dep1 : debug, when is []
    -> playbook/role/__init__.py:_load_role_data
       -> playbook/helpers.py:load_list_of_blocks
          found TASK: dep2 : debug, when is [False]
playbook/helpers.py:load_list_of_tasks
  -> playbook/role_include.py:get_block_list
     found TASK: master : include_role
playbook/role/__init__.py:_load_role_data
  -> playbook/helpers.py:load_list_of_blocks
     found task TASK: dep3 : debug, when is []
playbook/role_include.py:get_block_list
  -> playbook/role/__init__.py:compile
     task block [TASK: dep3 : debug], when is []
# so it's still correct here.

playbook/role/__init__.py:_load_role_data
  -> playbook/helpers.py:load_list_of_blocks
     found block BLOCK(uuid=3c18a002-ba38-edb0-5533-000000000015)(id=139940181569616)(parent=TASK: master : include_role), when is [False]
        found task TASK: dep3 : debug, when is [False]
# here it is, probably.

full debug log is here with these modifications

@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Jun 29, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
sf-project-io pushed a commit to redhat-cip/dci-ansible-agent that referenced this issue Mar 23, 2018
tripleo-inventory depends on the common role, however the role is not include
has it should when we use the include_role directive. Here we manually declare
the deploy_supplemental_node variable to avoid an undefined value during the
role execution

See:  ansible/ansible#23733

Change-Id: Ibc439b2248a8c80e10718eae47dbdbc3e0ba99e6
@sivel
Copy link
Member

sivel commented Apr 27, 2018

This issue was resolved in eeaa676 and included in the v2.3.2 release.

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Apr 27, 2018
sf-project-io pushed a commit to redhat-cip/dci-openstack-agent that referenced this issue Sep 24, 2018
tripleo-inventory depends on the common role, however the role is not include
has it should when we use the include_role directive. Here we manually declare
the deploy_supplemental_node variable to avoid an undefined value during the
role execution

See:  ansible/ansible#23733

Change-Id: Ibc439b2248a8c80e10718eae47dbdbc3e0ba99e6
@ansible ansible locked and limited conversation to collaborators Apr 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. include_role support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

7 participants