【发布时间】:2017-09-29 15:01:18
【问题描述】:
我正在尝试使用 ansible 来获取一个简单的 yaml 文件的内容并将它们模板化为一个更复杂的文件(.kitchen.yml 用于测试厨房,碰巧)
我的配置文件是这样的
test_platforms:
- ubuntu-16.04
- ubuntu-14.04
我想将其传递给.kitchen.yml,并让{{ test_platforms }} 中的键与特定图像相关联,例如
......
platforms:
- name: ubuntu-16.04
driver_config:
image: ubuntu:16.04 <--- This is the associated image
platform: ubuntu
- name: ubuntu-14.04
driver_config:
image: ubuntu:14.04 <--- This is the associated image
platform: ubuntu
......
我认为我可以通过查找来完成此操作,例如:
platforms:
{% for platform in test_platforms %}
- name: {{ platform }}
driver_config:
image: {{ lookup('ini', 'test_platforms section=docker file=platforms.ini') }}
platform: ubuntu
{% endfor %}
...给定一个platforms.ini:
[docker]
ubuntu-16.04=solita/ubuntu-systemd:16.04
ubuntu-14.04=ubuntu-upstart:14.04
我希望我可以使用参数化查找(即“Jinja“for”循环中的“测试平台”将在{{ test platforms }} 变量的值列表中读取,但这似乎不起作用。是有解决这个问题的方法,还是有更好的方法?这似乎是有人已经解决的问题之一,但是我进行的广泛谷歌搜索并没有发现任何东西,而且从文档中似乎并不明显.
【问题讨论】:
-
我对测试厨房不熟悉。你必须使用
platforms.ini吗?您能否将信息放入 ansible 变量文件中? -
澄清一下,这是围绕测试厨房的抽象。每次你想将它应用到你想测试的配置管理代码时,都需要添加很多样板配置。我的任务是构建一个可以自动为其他人执行此操作的包装器。