gpt4 book ai didi

Ansible 模棱两可的环境值

转载 作者:行者123 更新时间:2023-12-01 23:20:22 26 4
gpt4 key购买 nike

我在 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

所以我去查找了这个值的来源,并将它的所有实例都用引号括起来。或者我是这么想的。我仍然收到警告。

所以我去了代码中出现的地方,它似乎是这样的:
docker_container:
env: '{{ params | combine(extra_params, {"PORT": my_port|int + amount|int * 10 })}}'

这是一种用于处理同一容器的多个实例的设置,每个实例都有一个唯一的端口,以免相互干扰。

而且我不确定如何在不破坏该设置的情况下解决该问题。计算完成后可以再次转换为字符串吗?我应该提前做吗?这里最好的选择是什么?

最佳答案

作为 docker_container 的 ansible 文档env 下的模块状态

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.



所以你必须将你的结果转换为带引号的字符串。
env: '{{ params | combine(extra_params, {"PORT": (my_port|int + amount|int * 10) | string })}}'

关于Ansible 模棱两可的环境值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56544069/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com