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.
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. Sorry for the noise.