# Questions regarding porting action plugin from 1.8.x to 2.x

**URL:** <https://forum.ansible.com/t/questions-regarding-porting-action-plugin-from-1-8-x-to-2-x/22233>\
**Category:** Ansible Project\
**Created:** [August 8, 2016, 9:24am UTC](https://forum.ansible.com/t/questions-regarding-porting-action-plugin-from-1-8-x-to-2-x/22233 "2016-08-08T09:24:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Reuss](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@David\_Reuss](https://forum.ansible.com/u/David_Reuss)\
**Post date:** [August 8, 2016, 9:24am UTC](https://forum.ansible.com/t/questions-regarding-porting-action-plugin-from-1-8-x-to-2-x/22233/1 "2016-08-08T09:24:27Z")

</div>

Hi,

I’ve delayed porting my pre 2.0 action plugins, but now it’s finally time to attempt to upgrade to ansible 2.x, and i have a few questions.

The porting guide is rather lacking in details, especially regarding action plugins, but i have this really simple (but incredibly stupid) plugin which i either need to work for 2.x or someone suggest a workaround to get my desired behaviour, which basically is:

From a play - set a variable available on _all_ hosts, across _all_ plays – basically i need to be able to run a task anywhere - and have the variable stay the same across all hosts for the duration of the entire playbook.

Note i can’t convert everything to `-e`/extra vars from the command line, since a lot of the variables are dependent on other variables from plays/tasks/whatever, during the playbook execution.

Example usage:

- name: “Set variables”  
local\_action: inject\_vars  
args:  
is\_a: true  
is\_b: false

This is the meat of the plugin that currently works as i want it to:

class ActionModule(object):  
‘’’ Create inventory groups based on variables ‘’’

### We need to be able to modify the inventory

BYPASS\_HOST\_LOOP = True  
TRANSFERS\_FILES = False

def run(self, conn, tmp, module\_name, module\_args, inject, complex\_args=None, \*\*kwargs):

# … irelevant handling of args

inventory = self.runner.inventory  
allgroup = inventory.get\_group(‘all’)

for k, v in data.iteritems():  
allgroup.set\_variable(k, v)

result = {‘changed’: True, ‘data’: data}  
return ReturnData(conn=conn, comm\_ok=True, result=result)

Action plugins seems to have changed quite a bit in 2.x and i’m currently unable to get anything to work, that will allow me to access the _current_ inventory. There’s probably very good reasons for this (and my desired functionality probably conflicts quite a bit with what should be allowed).

I’ve tried gaining access to inventory, variable manager/tqm – no luck so far.

So - any ideas on how i can continue progress from here?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 10, 2017, 3:10am UTC](https://forum.ansible.com/t/questions-regarding-porting-action-plugin-from-1-8-x-to-2-x/22233/2 "2017-02-10T03:10:13Z")

</div>

Those are things only available 'pre fork', the plugin executes post  
fork. FYI, you can probably do same with set\_fact/delegate\_facts.
