我找不到做以下模板的方法:
- debug:
msg: {"registries":{"{{docker_registry.url}}":{"username":"{{docker_registry.user}}","password":"{{docker_registry.password}}"}}}Ansible自动检测json,并且不注入{{docker_registry.url}}的值:
"msg":{“注册表”:{ "{{docker_registry.url}}":{“密码”:"arGgyprRu8R3nu7JBIki",“用户名”:"autom“}}
插入引号会产生“不可序列化”错误。我加反斜杠,反斜杠是反斜杠。
对此模板或忽略json序列化有什么想法吗?
发布于 2019-03-20 17:46:32
引用这句话似乎很好:
- hosts: localhost
gather_facts: false
vars:
docker_registry:
url: http://foo.com
user: alice
password: secret
tasks:
- debug:
msg: '{"registries":{"{{docker_registry.url}}":{"username":"{{docker_registry.user}}", "password":"{{docker_registry.password}}"}}}'这一产出如下:
TASK [debug] **********************************************************************************
ok: [localhost] => {
"msg": {
"registries": {
"http://foo.com": {
"password": "secret",
"username": "alice"
}
}
}
}我可能会这样引用它,以使它更加可读性:
- debug:
msg: |
{
"registries": {
"{{docker_registry.url}}": {
"username": "{{docker_registry.user}}",
"password": "{{docker_registry.password}}"
}
}
}https://stackoverflow.com/questions/55266980
复制相似问题