2

The Problem

Currently, I am trying to develop an action plugin to call other modules to simplify and automate a task. (See my previous question for more details) Currently, I can't even get the plugin to run. I've seen that I need a module of the same name to exist for it to properly run, but it still fails when I have a blank file of the same name. What in the relationship between the module and the plug in am I missing?

Other Info

Just in case, I have misdiagnosed my error here is some installation infomation and example code for my plugin.

Installation

Module exists in ~/.ansible/plugins/modules
Plugin exists in ~/.ansible/plugins/action_plugin

Example Code

from ansible.plugins.action import ActionBase

class ActionModule(ActionBase):

    def run(self, tmp=None, task_vars=None):

        result = super(ActionModule, self).run(tmp, task_vars)

        result_modules = {}

        common_args = {}
        common_args['ucs_ip'] = self._task.args.get('ucs_ip')
        common_args['ucs_username'] = self._task.args.get('ucs_username')
        common_args['ucs_password'] = self._task.args.get('ucs_password')

        #Make LS Server
        module_args = common_args.copy()
        module_args['name'] = self._task.args.get('name')
        module_args['other_args'] = self._task.args.get('other_args')
        result_modules['lsServer'] = self._execute_module(module_name='ls_server_module', module_args=module_args, task_vars=task_vars, tmp=tmp)

        root_name = self._task.args.get('org_dn') + '/ls-' + self._task.args.get('name')

        #Make Vnic Ether
        for vnic in self._task.args.get('LAN', {}).get('VNIC'):
            module_args = common_args.copy()
            module_args['name'] = vnic.get('name')
            module_args['other_args'] = vnic.get('other_args')
            module_args['parent'] = root_name
            res['vnic_'+vnic.get('name')] = self._execute_module(module_name='vnic_ether_module', module_args=module_args, task_vars=task_vars, tmp=tmp)

            vnic_name = root_name + "/ether-" + vnic.get('name')

            #Make Vlan with VnicEtherIf
            for vlan in vnic.get('vlans'):
                module_args = common_args.copy()
                module_args['name'] = vlan.get('name')
                module_args['parent'] = vnic_name

Yaml file

---
- name: Test the Action Plugin
  connection: local
  hosts: localhost
  tasks:
  - name: run mod
    service_profile_module:
    name: ex
    other_args:
    creds: 
    LAN:
      VNIC:
      - name: ex_child
        other_args:
        vlans:
        - ex_child_child
      - name: ex_child_2
        other_args:
de-crob
  • 163
  • 1
  • 9

2 Answers2

2

Usually you would have this layout:

/path/to/project/playbook.yml
/path/to/project/library/module1.py
/path/to/project/library/module2.py
/path/to/project/library/action1.py
/path/to/project/action_plugins/action1.py

If you don't change default settings Ansible will look for modules under library directory near your playbook and for action plugins under action_plugins directory. Dummy action1.py is in library directory.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
1

Turns out the proper folder for the action plugin is ~/.ansible/plugins/action

de-crob
  • 163
  • 1
  • 9