Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using `start-at-task` in Ansible, is it possible to force an earlier task to always be run?

Tags:

ansible

I have a large complex Ansible provisioning setup, > 100 roles, > 30 inventory groups, etc... This is organised in the recommended way: top level playbooks, with a /roles folder, a /group_vars folder, etc...

Sometimes this fails part-way through, and I want to restart it from where it failed, using the --start-at-task command line switch.

However, I have several tasks that always need to run. These dynamically add hosts to the inventory, set variables that are needed later, etc...

Is there a way to force a task to always be run - or a role to always be applied, even when using --start-at-task?

I know about the always tag, but I think this only makes it run when filtering tasks by using --tag, not --start-at-task - unless someone knows differently?

Alternatively, is there some other way to structure things that would avoid this problem with --start-at-task?

like image 630
Duncan Lock Avatar asked Mar 01 '17 03:03

Duncan Lock


2 Answers

Unfortunately, it is not possible.

Currently you either have to use tags or bite the bullet, rely on idempotency and let all tasks re-run.


There were PRs and discussions to add such a functionality, but they never made it to the official Ansible release.

There is also an open issue asking for this feature, with a suggestiion, that always_run should enable running the task when using in conjunction with --start-at-task, but the discussion also withered away more than a year ago.

like image 126
techraf Avatar answered Nov 15 '22 10:11

techraf


The conclusion of the issue mentioned by techraf is that the good way to do it is by implementing a custom strategy: https://github.com/ansible/ansible/issues/12565#issuecomment-834517997

One has been implemented there (but I haven't been able to make it work with ansible-test)

Anyway it's a good start to implement a working solution and the only way possible as Ansible devs will not patch --start-at-task

like image 25
Jean Claveau Avatar answered Nov 15 '22 12:11

Jean Claveau