'Odd' Behavior with Role Dependencies when using import_role

32 views
Skip to first unread message

Todd Beauchemin

unread,
Mar 17, 2021, 4:30:56 PM3/17/21
to Ansible Project
We've seen what we'd classify as odd behavior when using import_role with roles that have dependencies defined under the meta directory.

The version of Ansible we are running is 2.9.10.

We have a few roles setup as follows
  • base_role
    • Does some basic setup of directories for storing facts and has some tasks focused around providing debug messages such as displaying known variables and facts as well as installing some utility packages
    • Has no dependencies and has 'allow_duplicates' explicitly set to 'false'
  • network_role
    • Handles configuration of network related items such as firewall, interface options, DNS resolver, etc.
    • Depends on base_role under meta/main.yaml and also has 'allow_duplicates' explicitly set to 'false'
  • cron_role
    • Handles configuration of AT/cron related items
    • Depends on base_role under meta/main.yaml and also has 'allow_duplicates' explicitly set to 'false'
We then have a default_config role which includes as dependencies the three above roles. 

When we have assigned the default_config_role role to a host everything works as expected. The base_role is only run once at the very beginning of execution followed by the cron_role and then the network_role as we have the roles listed as dependencies in alphabetical order. So:
  • base_role 
  • cron_role
  • network_role
When we however imported the default_config role into another role using the import_role directive the behavior totally changed. What we found was the following:
  • base_role was executed as it was a dependency from default_config_role
  • base_role was again executed as it was a dependency from cron_role
  • cron_role was then executed
  • base_role was executed for a third time as it was a dependency from network_role
  • network_role was then executed
There is only one place where we are performing the import_role directive and that is in the new role which is importing the default_config_role

My expectation, which maybe wrong, per documentation would be that the role being imported would still have it's dependencies processed as normal specifically with a reference to import_role being the same as using the role directive in a Playbook.

I can understand the duplication in execution if import_role was used multiple times importing the default_config_role but my expectation would still be that any dependencies from within the default_config_role would still be processed normally as well. So here I'd expect to see:
  • import 1 of default_config_role
    • base_role 
    • cron_role
    • network_role
  • import 2 of default_config_role
    • base_role 
    • cron_role
    • network_role
Is the behavior I'm seeing expected? 

Thanks!
~Todd

Matt Martz

unread,
Mar 17, 2021, 4:54:40 PM3/17/21
to ansible...@googlegroups.com
You didn't make it easy to reproduce, but I think I created a reproducer.  Based on my reproducer, your issue has been fixed in https://github.com/ansible/ansible/pull/72208

--
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-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d248a92e-995c-47d0-ac22-755ef82c0850n%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages