Skip to content

Callback Plugin to Save State #9491

@andrewjroth

Description

@andrewjroth

Summary

I am trying to find or create a callback plugin that will save what I'll call the "state" of a playbook at the start of each task. The goal here is to be able to resume the playbook execution by loading all of the existing variables from a "saved state" file and instructing which task to start with. I know that ansible-playbook already has a --start-at-task option, but this does not capture the variables that might have existed when the playbook failed.

For example, let's say a playbook has several tasks which do a variety of actions. Some of these actions will return data which are registered as a variable. Other tasks will also query the response data in order to set additional facts about the host. Think of reading a key file or discovering a public DNS name or load-balancer. When the playbook fails, all of the "registered" or "discovered" variables are lost, which makes it impossible to re-start the playbook execution from the failed task. The only option is to restart the entire playbook (which is fine, but it might take a long time or resources to get back to the failure again).

I'm imagining a callback plugin where all the in-scope variables are saved to a state file at the start of each task, and the name of the failed playbook is clear upon failure. To resume, the user need only execute the playbook again using something like:
ansible-playbook -e @saved-state-vars.yml playbook-file.yml --start-at-task "The name of the Task"

Is this something that exists already?

If not, is there a way to list all variables from a CallbackModule method like v2_playbook_on_task_start? I'm using context_demo as a starting point. If someone could demonstrate how to access variables from here, that would be very helpful!

Thanks in advance!

Issue Type

Feature Idea

Component Name

plugins.callback

Additional Information

No response

Code of Conduct

  • I agree to follow the Ansible Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureThis issue/PR relates to a feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions