简体   繁体   English

AnsibleModule对象不可调用错误

[英]AnsibleModule object is not callable error

My playbook is as follows 我的剧本如下

---
- hosts: nodes
  become: yes
  tasks:
  - name: Run Shell Script to get IPs with 4xx and 5xx errors

    script: /home/ubuntu/ips.sh
    args:
      chdir: /home/ubuntu
    register: ips

  - set_fact:
       iperrors: "{{ groups.nodes | map('extract', hostvars, 'ips') | map(attribute='stdout') | join('') }}"
    run_once: true
    delegate_to: localhost


  - name: Python Custom Module to get Top 5 Ips
    5ips:
      iperrors: "{{iperrors}}"
    run_once: true
    delegate_to: localhost
    register: 5ip

I have written a custom module 5ips But when I execute playbook it throws an error as follows 我已经编写了一个自定义模块5ips,但是当我执行剧本时,它会引发如下错误

TASK [Python Custom Module to get Top 5 Ips] ***************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'AnsibleModule' object is not callable
fatal: [54.183.110.130 -> localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1545815995.35-86175850009970/AnsiballZ_5ips.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1545815995.35-86175850009970/AnsiballZ_5ips.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1545815995.35-86175850009970/AnsiballZ_5ips.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_5ips_payload_7Vi28k/__main__.py\", line 41, in <module>\n  File \"/tmp/ansible_5ips_payload_7Vi28k/__main__.py\", line 12, in main\nTypeError: 'AnsibleModule' object is not callable\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc"

my 5ips.py is as follows 我的5ips.py如下

#!/usr/bin/python

from ansible.module_utils.basic import *

def main():
    fields = {
        "iperrors" :{"required":True, "type":"str"}
        }
    module = AnsibleModule(argument_spec = fields)
    iperrors = module.params['iperrors']
    module(iperrors)

    if IpList !=0:
        module.exit_json(changed = True, msg = "top5 ips done")
    else:
        module.fail_json(changed = False, Error = "Something went wrong in Top5IPS.py")

def module(iperrors):
    ipErrors ={}
    IpList=[]

the input iperrors im giving is a multiline string. 输入的iperrors im给出的是多行字符串。 Im not sure exactly where the error is? 我不确定错误在哪里?

Check the "module_stderr" key in the output. 检查输出中的“ module_stderr”键。 Near the end it says "'AnsibleModule' object is not callable\\n" 在结尾处,它说“'AnsibleModule'对象不可调用\\ n”

I'm not super familiar with custom ansible modules, but it looks like the way to write them has changed, check the new docs here: https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#developing-modules-general 我对自定义ansible模块不太熟悉,但是看起来编写它们的方式已经改变,请在此处查看新文档: https : //docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#developing -模块-通用

Alternatively, you could try using an older (<2.0, probably) version of ansible. 另外,您可以尝试使用旧版本(可能小于<2.0)的ansible。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM