首页 > 解决方案 > ansible action 插件扩展 ansible fact

问题描述

我一直在尝试使用此处的内容将主机名传递给模块

在模块代码中使用 ansible_facts

我有下面的代码,通常会创建一个事实,我可以在使用模板或复制模块后远程复制文件。

#!/usr/bin/python

import custommodule 

# ...

hostname = {{ ansible_nodename }}  # hostname should come from ansible_nodename fact. 

custom_content = custommodule.render(hostname)

facts = dict()
facts['custom_content'] = custom_content
args = {
    'changed': False,
    'ansible_facts': {'custom_facts': facts},
}
module.exit_json(**args)

问题是如何确保变量由我不知道如何实现hostname的事实填充。ansible_nodename

我怎么能修改这个

标签: ansibleansible-2.x

解决方案


推荐阅读