我找不到以下模板的方法:
- debug:
msg: {"registries":{"{{docker_registry.url}}":{"username":"{{docker_registry.user}}","password":"{{docker_registry.password}}"}}}
Ansible自动检测json,并且不注入{{docker_registry.url}}的值:
“ msg”:{ “注册表”:{ “ {{docker_registry.url}}”:{ “密码”:“ arGgyprRu8R3nu7JBIki”, “用户名”:“自动” } } }
使用引号引起“无法序列化”错误。我添加反斜杠,反斜杠反斜杠。
有任何想法将此模板化或忽略json序列化吗?
答案 0 :(得分:2)
引用它似乎可以正常工作:
- 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}}"
}
}
}