Setting variables from within a plugin

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.