Ansible 模棱两可的 env 值 [英] Ansible ambiguous env value
问题描述
我在 Ansible 中收到以下警告:
I'm getting the following warning in Ansible:
[WARNING]: Non-string value found for env option. Ambiguous env options should be wrapped in quotes to avoid YAML parsing. This will become an error in Ansible 2.8. Key: PORT; value will be treated as: 12345
所以我去查找这个值的来源并将它的所有实例都用引号括起来.或者我是这么想的.我仍然收到警告.
So I went and looked up the origin of this value and wrapped all instances of it in quotes. Or so I thought. I'm still getting the warning.
于是我去了代码中出现的地方,好像是这样的:
So I went to the place in the code where it appeared and it seems to be this:
docker_container:
env: '{{ params | combine(extra_params, {"PORT": my_port|int + amount|int * 10 })}}'
这是一种处理同一容器的多个实例的设置,每个实例都有一个唯一的端口,以免相互干扰.
This is a setup for dealing with multiple instances of the same container, each getting a unique port, as to not interfere with one another.
而且我不确定如何在不破坏该设置的情况下解决该问题.计算完成后是否可以再次转换为字符串?我应该提前做吗?这里最好的选择是什么?
And I'm not sure how to fix that without breaking that setup. Can it be cast to string again after the calculation is done? Should I do it beforehand? What's the best option here?
推荐答案
作为 env 状态下的noreferrer">docker_container 模块
As the ansible documentation for the docker_container module under env
states
可能被 YAML 解析器解析为数字、布尔值或其他类型的值必须被引用(例如 "true"
)以避免数据丢失.
Values which might be parsed as numbers, booleans or other types by the YAML parser must be quoted (e.g.
"true"
) in order to avoid data loss.
因此您必须将结果转换为带引号的字符串.
so you have to convert your result to a quoted string.
env: '{{ params | combine(extra_params, {"PORT": (my_port|int + amount|int * 10) | string })}}'
这篇关于Ansible 模棱两可的 env 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!