awx icon indicating copy to clipboard operation
awx copied to clipboard

Rerun Jobs on Failed Hosts

Open LukeShortCloud opened this issue 9 years ago • 35 comments

ISSUE TYPE
  • Feature Idea
COMPONENT NAME
  • API
  • UI
SUMMARY

It would be great to see AWX Jobs be able to re-run a Template only on hosts that failed. This would be similar to how Ansible handles it via using "--limit @site.retry" for failed hosts. In the UI, this could be another button similar to the existing rocket ship that denotes launching the entire Job on all hosts again. This will help lower the load on the Ansible Tower nodes as it does not need to process the successful hosts again.

For brownie points, it would also be great to have this integrated into both a normal Job/Template and the newer Workflow Template. A Workflow could look like: "If Job fails, then automatically only re-run on failed hosts."

ENVIRONMENT
  • AWX version: 2017-09
  • Ansible version: 2.4.0
STEPS TO REPRODUCE

Run a Template. If the Job fails on some of the hosts there is no way to quickly/automatically re-run the Template only on the failed hosts.

EXPECTED RESULTS

If a Job fails, there should be an option to "Rerun on, and limit to, failed hosts."

ACTUAL RESULTS

The Template will need to be re-run on all hosts in the specified Inventory, even though some of them already had a successful run and do not need the Playbook to be run on them again.

LukeShortCloud avatar Sep 20 '17 14:09 LukeShortCloud

+1

hudecof avatar Sep 22 '17 11:09 hudecof

+1

senorsmile avatar Sep 24 '17 14:09 senorsmile

Proposed API mechanism:

Leverage the /api/v2/jobs/N/restart/ endpoint. Accept a flag, like "failed_hosts_only": true.

We should be able to easily obtain the hosts with failed status, while also down-selecting from the hosts from the original job. /api/v2/jobs/46/job_host_summaries/?job__status=failed, QED.

The failed-hosts-relaunched job will use the --limit parameter, as this is how the .retry file feature works in Ansible core. This will simply consist of a listing of the hosts to run against.

RBAC: exact same permission required as simple relaunch, since the action is only a subset of what relaunch is.

AlanCoding avatar Oct 06 '17 13:10 AlanCoding

Endpoint is /api/v2/jobs/N/relaunch/.

The new limit would be the equivalent of ",".join(host_names) for each host_name in api/v2/jobs/N/job_host_summaries/?failed=true. It would also be possible relaunch on hosts meeting other criteria, e.g.:

  • api/v2/jobs/N/job_host_summaries/?changed__gt=0 to relaunch against hosts that changed, to check if your playbook is idempotent.
  • api/v2/jobs/N/job_host_summaries/?dark__gt=0 to relaunch against hosts that were previously unreachable.

This approach would include hosts that were created during the previous playbook run via add_host, even though those hosts aren't in the original inventory, so we'll need to evaluate if we want that and what the side effects are.

I would propose posting {"hosts": "<status>"} to /api/v2/jobs/N/relaunch/, where <status> could be one of "all" (the current default for relaunch), "failed", "ok", "changed" or "dark" (and maybe "skipped" or "processed" if there are any conceivable use cases for those).

cchurch avatar Oct 09 '17 03:10 cchurch

^ I support this proposal.

AlanCoding avatar Oct 09 '17 11:10 AlanCoding

@trahman73 thinking about the UI aspect...

What if the relaunch button would pop up another window if you hovered over it. That could then be the place where we offer the options of "retry on: ok, changed, failed, etc." Just wanted to throw that out there, because the decision to allow relaunch for all status types will impact your side of things.

AlanCoding avatar Oct 09 '17 15:10 AlanCoding

@AlanCoding image

trahman73 avatar Oct 10 '17 16:10 trahman73

That looks good for a menu once you're retrying on a subset of hosts. I think that would be good as long as it didn't interfere with the current flow of relaunching, which you click it once, it relaunches normally, and it keeps you on the same page. I know people have complained when we broke that functionality in that past. If that is a menu you can get from a hover and click or something like that, then that looks great!

(reading "Cleanup Deleted Data") just a heads up, if that's a system job, this feature would not apply to it. AFAIK, this would only apply to relaunches of playbook runs, which excludes project/inventory updates, system jobs, workflow jobs, etc.

AlanCoding avatar Oct 10 '17 16:10 AlanCoding

@AlanCoding Based on your feedback, we can try something like this on click or on hover. image

trahman73 avatar Oct 10 '17 18:10 trahman73

I think that looks really good.

AlanCoding avatar Oct 10 '17 18:10 AlanCoding

@AlanCoding @trahman73 instead of "Ok" I think we should maybe have that be "All"?

jlmitch5 avatar Oct 10 '17 19:10 jlmitch5

"Ok" is a different meaning than "All" because "All" includes the failed hosts as well. "All" would just be the existing relaunch functionality.

So if clicking directly on the rocket does the "all" retry, maybe the text would be more clear if it said "RETRY ON ONLY", or something like that

AlanCoding avatar Oct 10 '17 19:10 AlanCoding

Question for UI, ping @jlmitch5:

I am considering if it would be valuable to provide the job summary data for a GET to the /relaunch/ endpoint. If so, I'm wondering what would be the right granulaity for this.

A mock of the response, giving the number of hosts for each:

{
    "passwords_needed_to_start": [],
    "host_summary": {
        "ok": 4,
        "changed": 2,
        "failed": 1,
        "unreachable": 0
    }
}

We could list the hostnames for each, which is what we would use for --limit, but I don't actually see any use for this, and it could be burdensome for large inventories.

I'm thinking that you may want to grey out an option if the number of hosts is 0. I will also consider having the API validate for this scenario, so that we don't relaunch if the relaunch would target an empty host list.

This approach would require that you fire off a GET to the /relaunch/ endpoint in order to populate the hover-over dropdown. Does this seem like it would fit nicely into your implementation?

@trahman73 I noticed that we may want to add "unreachable" to the list. Consider the Ansible playbook summary:

ok=1    changed=0    unreachable=0    failed=0

AlanCoding avatar Oct 16 '17 14:10 AlanCoding

Question: would we want integration of this feature into workflows? That is, have a workflow where you have the "failed" branch relaunch on only the failed hosts. Initial impression is that this will be very non-trivial @wenottingham

AlanCoding avatar Oct 16 '17 14:10 AlanCoding

I think to do that reliably in workflows, you'd need something like a single workflow step with semantics of "relaunch until all succeed, max number of relaunches = N". That's a much bigger backend concept that I wouldn't create directly as part of this.

wenottingham avatar Oct 16 '17 14:10 wenottingham

@AlanCoding I added an ALL option as the UX for this really gets grouped into our normal relaunch flow. image

trahman73 avatar Oct 16 '17 15:10 trahman73

Discovered a new wrinkle in this. Testing environment:

PLAY RECAP **********************************************************************************************************************************************************************
1                          : ok=2    changed=0    unreachable=0    failed=1   
2                          : ok=3    changed=1    unreachable=0    failed=0   
3                          : ok=2    changed=0    unreachable=1    failed=0   
4                          : ok=3    changed=1    unreachable=0    failed=0   
5                          : ok=2    changed=0    unreachable=1    failed=0   
6                          : ok=2    changed=0    unreachable=0    failed=0   

$ cat status/random_status.retry 
1
3
5

This is the default Ansible "retry" style. You can see that unreachable hosts are not counted as failed, but they are included in the retry file.

This presents a challenge for us in terms of how to communicate this to the user.

AlanCoding avatar Oct 16 '17 20:10 AlanCoding

Then when relaunching on 'failed', include unreachable by default? (may also need to roll changed into 'ok', in terms of host status)

wenottingham avatar Oct 17 '17 03:10 wenottingham

Then when relaunching on 'failed', include unreachable by default? (may also need to roll changed into 'ok', in terms of host status)

Agree with the first proposition here. That will just have to be documented, and I was going to look into using a mapped choice, so that I can apply a label and say descriptively "Retry on failed and unreachable hosts".

On the 2nd item, "changed" hosts are a subset of "ok" hosts, right?

AlanCoding avatar Oct 17 '17 11:10 AlanCoding

That's my understanding at the host level - changed is a subset of OK, unreachable is a subset of failed.

wenottingham avatar Oct 17 '17 13:10 wenottingham