我的剧本如下
---
- 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
我已经编写了一个自定义模块5ips,但是当我执行playbook时,它会抛出如下错误
^{pr2}$5年款ips.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=[]
我给出的输入iperrors是一个多行字符串。我不确定错误到底在哪里?在
检查输出中的“模块”键。在结尾处显示“AnsibleModule”对象不可调用\n
我对自定义的ansible模块不是很熟悉,但是编写它们的方式似乎已经改变了,请检查这里的新文档:https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#developing-modules-general
或者,您可以尝试使用ansible的旧版本(可能是<;2.0)。在
相关问题 更多 >
编程相关推荐