Execution order of "import_role" and "include_role"?

Hi,

I have an Ansible role where I want to run another Ansible role much like a subroutine. So, in the middle of a playbook (tasks/main.yaml) I have an “import_role” task to run that other role. I used to have Ansible 2.9 or so, where this worked nicely, but recently upgraded Ansible to 2.18.0, and now, the imported role gets run at the start of my playbook, ie, at the start of my role, which fails everytime because the environment is not yet properly set up at that point - there’s a reason why I don’t just “depend” on the other role via meta.yml. Did I miss something, or how can I make the role to execute in order, not at the beginning? I also tried “include_role”, but that didn’t help, either.

What gives?

While imports do get executed at ‘compile’ time, the tasks for the role should only execute in the order they appear in the play. So aside from the import/include itself running at different times, the tasks included/imported should run as they are placed. There have been changes to imports and includes in many versions, but the task execution order should not have changed. Can you provide an example/simple reproducer?

I’ve just tried to reproduce the situation with two brand-new roles, and it worked as it should. I also found my problem with the other role: I had mentioned the imported role as a dependency in the meta.yml. :man_facepalming: Sorry for the noise.

No worries, there is a reason my avatar is a rubber ducky!

1 Like