我创建了一个名为“ render”的ansible模块,它将文件的内容转换为列表。如下所示,
#!/usr/bin/python
import os
import subprocess
from ansible.module_utils.basic import AnsibleModule
stored_path = < my path to file >
def file_list():
with open(stored_path, 'r') as fr:
user_data = fr.readlines()
return user_data
def main():
module = AnsibleModule(argument_spec={})
result = dict(
result=''
)
user_data = file_list()
module.exit_json(**result)
if __name__ == '__main__':
main()
我从中调用此模块的剧本,其代码如下所示,
-
name: Random tests on Ansible
hosts: "{{ hostval }}"
gather_facts: no
vars:
user_data_file: <path to file>
user_data: ""
tasks:
- name: collect file and related objects
render:
register: result
- debug: var=result
这里“ render”是ansible模块。
我的问题是如何将变量“ user_data”的值返回到调用此ansible模块的ansible剧本中?