我正在尝试学习并为 Ansible 创建一个 python 模块。我正在关注此页面:Medium.com
这是本地模块,所以我只想使用./library/module.py.
---
- hosts: localhost # I've used 127.0.0.1 here also
connection: local
vars:
- Test: "This is a test"
tasks:
- name: set result
set_fact:
result: "set"
- name: Test that my hello_world module works
hello_world:
register: result
- debug: var=result
...
Run Code Online (Sandbox Code Playgroud)
该模块是一个简单的 python 脚本,用于打印“Hello World”。它是./library/hello_world.py
#!/usr/bin/python
from ansible.module_utils.basic import *
def main():
module = AnsibleModule(argument_spec={})
theReturnValue = {"hello": "world"}
module.exit_json(changed=False, meta=theReturnValue)
if __name__ == '__main__': …Run Code Online (Sandbox Code Playgroud)