Delegation in Action Plugins

15 views
Skip to first unread message

Arti

unread,
Aug 27, 2015, 4:49:36 PM8/27/15
to Ansible Project
There is surprisingly (and sometime frustratingly) little documentation on Ansible action_plugins. I am trying to write an action plugin for a module that uses delegation. Is there a way to accomplish this? Would greatly appreciate any input

This is an example of a module I have:-

- name: "create database user"
    db_user:
      host: "{{ groups['servers'].0 }}"
      user: "{{ root_user }}"
      password: "{{ root_password }}"
   delegate_to: "{{ groups['servers'].0 }}"

And my action plugin is:-

class ActionModule(object):

    def __init__(self, runner):
        self.runner = runner

    def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
        parsed_args = parse_kv(module_args)
        options = {
            key: parsed_args.get(key) for key in ["host", "user", "password"]
        }    
        args = " ".join(
            "{}='{}'".format(key, value) for key, value in options.items()
        )
        return self.runner._execute_module( conn, tmp, 'db_user', args, inject=inject,)



Thanks
Reply all
Reply to author
Forward
0 new messages