Ansible 在库存中使用变量

用户198235

我有一个带有以下私钥的 ec2 实例 [10.0.0.100]:test01.pem

我有一个带有以下私钥的 ec2 实例 [10.0.0.200]:test02.pem

我的个人电脑中有一个主机文件:

主机

[production]
10.0.0.100 ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/ok/test01.pem
10.0.0.200 ansible_ssh_user=ubuntu ansible_ssh_private_key_file=/ok/test02.pem

我想要类似的东西:hosts

[vars]
test01_pem=/ok/test01.pem
test0_pem=/ok/test02.pem

[production]
10.0.0.100 ansible_ssh_user=ubuntu ansible_ssh_private_key_file=$test01_pem
10.0.0.200 ansible_ssh_user=ubuntu ansible_ssh_private_key_file=$test02_pem

我怎样才能做到这一点?

Zeitounator

与其他 ansible 定义一样,您必须使用 jinja2 模板。此外,您需要声明您的“全局”变量附加到“所有”组。我建议您查看库存文档以了解更多信息。

作为从您的 ini 库存开始的快速示例,这将给出:

[all:vars]
test01_pem=/ok/test01.pem
test02_pem=/ok/test02.pem

[production]
10.0.0.100 ansible_ssh_user=ubuntu ansible_ssh_private_key_file="{{ test01_pem }}"
10.0.0.200 ansible_ssh_user=ubuntu ansible_ssh_private_key_file="{{ test02_pem }}"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章