# Setting variables from within a plugin

**URL:** <https://forum.ansible.com/t/setting-variables-from-within-a-plugin/26547>\
**Category:** Ansible Project\
**Created:** [January 24, 2018, 1:41am UTC](https://forum.ansible.com/t/setting-variables-from-within-a-plugin/26547 "2018-01-24T01:41:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thebearup](https://avatars.discourse-cdn.com/v4/letter/t/ecae2f/32.png) [@thebearup](https://forum.ansible.com/u/thebearup)\
**Post date:** [January 24, 2018, 1:41am UTC](https://forum.ansible.com/t/setting-variables-from-within-a-plugin/26547/1 "2018-01-24T01:41:31Z")

</div>

Any pointers on writing data to a task variable from within a plugin? I’ve looked at the host\_group\_vars plugin (which just returns a dictionary) and at the templar (set\_available\_variables). I can get the current variables and “write” to them but the variable I set doesn’t seem to be persisted. Most likely I’m getting a copy of the actual vars.

Background: I’m working on a solution to do phased deployment over sequentialruns. E.g. target group A on this run, then group B on the subsequent run. This consists of a lookup plugin (which determines which group to target) and a strategy plugin (which captures/manages the state of one run to the next). All I need at the moment is to persist the group selected by the lookup plugin so that it can be found by the strategy plugin. I could write this to a file on disk or a static variable etc, but writing to a var seemed like the cleanest approach.
