Ansible动态库存-如何将值注入库存来源

时间:2020-02-20 13:18:36

标签: ansible yaml ansible-inventory ansible-awx

首先是一些背景。

我有一个动态清单,可以从外部来源提取数据。我有各种各样的剧本,它们使用此清单来完成一些任务,并且可以通过ansible-playbook临时命令或通过Ansible AWX来运行它们。

在测试与托管主机的连接时,我可以运行诸如ansible -m ping -i inventories/ linuxnode.servers.fqdn之类的命令,这完全可以正常工作。我还在AWX中进行了广告资源同步,效果也很好。

此方法使用YAML格式的inventory source中的inventories/,其中我将一些值传递给自定义清单脚本the_custom_plugin。示例YAML文件datacenter1.yml

plugin: the_custom_plugin
url: "https://externalapp.servers.fqdn"
username: poweruser
privatekey: secretpassword

现在,出于明显的安全原因,我想删除用户名和密码,而是将它们隐藏起来:

  1. 通过ansible-playbook命令运行时在环境变量中;和
  2. 通过AWX运行时,在AWX凭据中。

问题是,似乎没有办法将值注入清单资源中的变量。甚至像这样的非常简单的更改也不起作用(即自定义插件失败):

plugin: the_custom_plugin
url: "https://externalapp.servers.fqdn"
temp_username: poweruser
username: "{{ temp_username }}"
privatekey: secretpassword

使用外部插件的清单源文件是否有secret YAML syntax?还是自定义插件代码中的问题?我非常困惑,这甚至行不通:

temp_username: poweruser
username: "{{ temp_username }}"

干杯。

0 个答案:

没有答案