Action Plugin 和 Ansible Module 之间有什么关系?

What is the relationship between the Action Plugin and an Ansible Module?

问题

目前,我正在尝试开发一个动作插件来调用其他模块来简化和自动化任务。 (查看我的 了解更多详情)目前,我什至无法获得 运行 的插件。我已经看到我需要一个同名的模块才能正确 运行,但是当我有一个同名的空白文件时它仍然失败。我错过了模块和插件之间的什么关系?

其他信息

以防万一,我误诊了我的错误,这里是我的插件的一些安装信息和示例代码。

安装

模块存在于 ~/.ansible/plugins/modules
插件存在于 ~/.ansible/plugins/action_plugin

示例代码

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 文件

---
- 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:

原来动作插件的正确文件夹是 ~/.ansible/plugins/action

通常你会有这样的布局:

/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

如果您不更改默认设置,Ansible 将在您的剧本附近的 library 目录下查找模块,并在 action_plugins 目录下查找操作插件。虚拟 action1.pylibrary 目录中。