Ansible模糊环境值
我在Ansible收到以下警告:Ansible模糊环境值,ansible,Ansible,我在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 所以我去查找这个值的来源,并将它的所有实例都用引
[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
所以我去查找这个值的来源,并将它的所有实例都用引号括起来。至少我是这么想的。我仍然得到警告
所以我去了代码中出现它的地方,它似乎是这样的:
docker_container:
env: '{{ params | combine(extra_params, {"PORT": my_port|int + amount|int * 10 })}}'
这是一个用于处理同一容器的多个实例的设置,每个实例都有一个唯一的端口,以避免相互干扰
我不知道如何在不破坏设置的情况下解决这个问题。计算完成后,是否可以再次将其转换为字符串?我应该事先做吗?这里的最佳选项是什么?正如
env
下模块的ansible文档所述
YAML解析器可能解析为数字、布尔值或其他类型的值必须引用(例如“true”
),以避免数据丢失
因此,您必须将结果转换为带引号的字符串
env: '{{ params | combine(extra_params, {"PORT": (my_port|int + amount|int * 10) | string })}}'