简体   繁体   English

Ansible 模块开发:没有名为 ansible.runner 的模块?

[英]Ansible Module Development: No module named ansible.runner?

I'm trying to write my first module in Ansible, which is essentially a wrapper around another module.我正在尝试用 Ansible 编写我的第一个模块,它本质上是另一个模块的包装器。 Here is my module:这是我的模块:

#!/usr/bin/python
import ansible.runner
import sys

def main():
    module.exit_json(changed=False)

from ansible.module_utils.basic import *
main()

and here is the error it gives me (stripped from 'msg'):这是它给我的错误(从'msg'中删除):

ImportError: No module named ansible.runner导入错误:没有名为 ansible.runner 的模块

I am on ubuntu and installed ansible with aptitude, version is 1.9.1 Any ideas?我在 ubuntu 上并使用 aptitude 安装了 ansible,版本是 1.9.1 有什么想法吗?

Modules have to essentially be standalone.模块本质上必须是独立的。 The boilerplate gets injected at runtime (the text of the boilerplate replaces the import at the bottom), and the combined text of the module + boilerplate is squirted to the remote machine and run there.样板在运行时被注入(样板的文本替换了底部的导入),并且模块 + 样板的组合文本被喷射到远程机器并在那里运行。 As such, you can't import things from ansible core like the runner (unless you install ansible on the remote machine- don't be that guy).因此,您不能像 runner 一样从 ansible 核心导入东西(除非您在远程机器上安装 ansible - 不要成为那个人)。 "module" is one of the items that you have to create from stuff defined in the boilerplate. “模块”是您必须根据样板文件中定义的内容创建的项目之一。 Here's a sample module skeleton I wrote:这是我编写的示例模块骨架:

#! /usr/bin/python

import json

def main():
    module = AnsibleModule(
        argument_spec = dict(
            state     = dict(default='present', choices=['present', 'absent'])
        ),
        supports_check_mode = True
    )

    p = module.params

    changed = False

    state = p['state']

    if not module.check_mode:
        # do stuff
        pass

    #module.fail_json(msg='it broke')

    module.exit_json(changed=changed)

from ansible.module_utils.basic import *
main()

I just checked a module I wrote a while back and I don't have such an import line.我刚刚检查了我不久前写的一个模块,但我没有这样的导入行。 The only import I have is from ansible.module_utils.basic import * .我唯一的导入是from ansible.module_utils.basic import * The module object I create myself in main :我在main创建的module对象:

module = AnsibleModule(
    argument_spec=dict(
        paramA=dict(required=True),
        paramB=dict(required=False),
        paramC=dict(required=False),
    ),
    add_file_common_args=True,
    supports_check_mode=True
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从tar安装了Ansible。 没有名为ansible.runner的模块错误 - Ansible installed from tar. No module named ansible.runner error ModuleNotFoundError: No module named 'server_types' Ansible 模块开发 - ModuleNotFoundError: No module named 'server_types' Ansible module development 导入错误:通过 PIP 安装 Ansible 2.9 后没有名为 ansible 的模块 - ImportError: No module named ansible after installing Ansible 2.9 via PIP Ansible 复制和同步模块失败:没有名为 ansible 的模块 - Ansible copy and synchronize modules fail: No module named ansible Ansible 因 ModuleNotFoundError 失败:没有名为“pexpect”的模块 - Ansible fails with ModuleNotFoundError: No module named 'pexpect' ImportError:没有名为syslog,ansible,edison的模块 - ImportError: No module named syslog, ansible, edison Ansible - Vmware 来宾 - 没有模块命名请求 - Ansible - Vmware guest - No module named requests Ansible错误 - 没有名为packaging.version的模块 - Ansible error - No module named packaging.version 自制Ansible模块具有“设置错误:没有名为FabricVcon的模块” - Homemade Ansible Module has “setup error: No module named FabricVcon” “ ImportError:没有名为xhaus的模块” Python模块从ansible导入错误 - “ImportError: No module named xhaus” Python module importing error from ansible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM