我是 ansible 的新手,我在从 ansible 角色的 json 文件中读取值时遇到问题。我的变量具有如下值:
{
"queue": {
"first": {
"car": "bmw",
"year": "1990",
"model": "x3",
"color": "blue"
},
"second": {
"car": "bmw",
"year": "2000",
"model": "318",
"color": "red"
}
}
}
我试图打印颜色的值只是为了将它与其他一些变量进行比较。我曾经with_dict
迭代 json 对象(存储在名为 jsonVar 的变量中),如下所示:
- name: test loop
with_dict: "{{jsonVar}}"
shell: |
if echo "blue" | grep -q "${{item.value.color}}" ; then
echo "success"
到目前为止,从 if 语句中获取颜色值从 json 到“蓝色”的比较还没有运气。我想知道我是否做错了什么?提前致谢!