Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback Plugin to Save State #9491

Open
1 task done
andrewjroth opened this issue Dec 30, 2024 · 1 comment
Open
1 task done

Callback Plugin to Save State #9491

andrewjroth opened this issue Dec 30, 2024 · 1 comment
Labels
feature This issue/PR relates to a feature request

Comments

@andrewjroth
Copy link

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
@felixfontein
Copy link
Collaborator

I think you should rather ask this in the Ansible forum, since this is not specific to community.general at all: https://forum.ansible.com/

@ansibullbot ansibullbot added the feature This issue/PR relates to a feature request label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This issue/PR relates to a feature request
Projects
None yet
Development

No branches or pull requests

3 participants