Hi,

I'm trying to get some clarity on the expected behaviour of the following 
scenario. I've included the file contents of a demonstration set of roles 
below. My question is about the behaviour of the include vs import changes 
between 2.3.2.0 and 2.4+.  On 2.3.2.0, the included
role would be executed as part of roles/first/tasks/main.yml.  But in 2.4+, 
the included role is never executed at all, seemingly because the excluded 
second role (which has a dependency on first) is excluded.  

My expectation is the 2.3.2.0 behaviour where as first explicitly included, 
the included will be executed at that point.

Note: included isn't specified as a meta dependency of first as it is 
required to run at a particular point in the execution of first.  The second 
role is skipped for conditional reasons but I don't want that to affect the 
inclusion in the first role.  It's a bit unnerving if a role further down 
the playbook can have an impact on what a previous role in the playbook 
actually executes. i.e. I could have a playbook that does everything I 
want, then add a new conditional role to the playbook and break the 
original functionality.

Is this behaviour correct? Should I be changing the include_role in first 
to be import_role or doing something different, or is there something not 
right?

Running on ubuntu 14.04 and 16.04 with python 2.7.11.

Any advice would be greatly appreciated.

Many thanks,

Dave

With ansible 2.3.2.0, the "debug message from included" is executed as 
expected:

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


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


TASK [first : first debug from first] 
**********************************************************************************************************************
ok: [localhost] => {
    "msg": "first debug from first"
}


TASK [included : debug message from included] 
**************************************************************************************************************
ok: [localhost] => {
    "msg": "debug message from included"
}


TASK [first : last debug from first] 
***********************************************************************************************************************
ok: [localhost] => {
    "msg": "last debug from first"
}


TASK [included : debug message from included] 
**************************************************************************************************************
skipping: [localhost]


TASK [second : Debug from second] 
**************************************************************************************************************************
skipping: [localhost]


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


With ansible 2.5.0, the "debug message from included" is skipped:

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


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


TASK [first : first debug from first] 
**********************************************************************************************************************
ok: [localhost] => {
    "msg": "first debug from first"
}


TASK [first : include_role] 
********************************************************************************************************************************


TASK [included : debug message from included] 
**************************************************************************************************************
skipping: [localhost]


TASK [first : last debug from first] 
***********************************************************************************************************************
ok: [localhost] => {
    "msg": "last debug from first"
}


TASK [second : Debug from second] 
**************************************************************************************************************************
skipping: [localhost]


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


To run the playbook:
ansible-playbook -i "localhost," -c local playbook.yml

playbook.yml
---

- hosts: localhost
  roles:
    - { role: first }
    - { role: second, when: some_variable | default(false) }

roles/first/tasks/main.yml
---


- name: first debug from first
  debug:
    msg: "first debug from first"


- include_role: name=included


- name: last debug from first
  debug:
    msg: "last debug from first"

roles/second/tasks/main.yml
---


- name: Debug from second
  debug:
    msg: "Hello from second"


roles/second/meta/main.yml
---


dependencies:
- { role: first }


roles/included/tasks/main.yml
---


- name: debug message from included
  debug: 
    msg: "debug message from included"




-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5cc17809-5793-419a-8043-c6962f7c5657%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to