Ansible-在映射到列表的字典上执行查找,但将列表中的值视为字符串

Ansible-在映射到列表的字典上执行查找,但将列表中的值视为字符串,ansible,Ansible,在字典MyDict中,嵌套列表中的第二个字典将name键设置为整数值(101)。因此,debug语句中的查找返回false。有没有办法让查找将列表中的值转换为字符串,以便在本例中返回true?谢谢 --- - hosts: localhost vars: MyDict: - name: Bob - name: 101 <-- This is a value entered by a user, which happens to

在字典MyDict中,嵌套列表中的第二个字典将name键设置为整数值(101)。因此,debug语句中的查找返回false。有没有办法让查找将列表中的值转换为字符串,以便在本例中返回true?谢谢

---
 - hosts: localhost
  
   vars:
     MyDict:
       - name: Bob
       - name: 101      <-- This is a value entered by a user, which happens to be an integer

     findname: "101"    <-- This is a string i wish to find in the dictionary

   tasks:
    - debug: msg="{{ findname in MyDict | map(attribute='name') | list }}"   <-- I want the lookup to return true

---
-主机:本地主机
变量:
MyDict:
-姓名:鲍勃

-名称:101将列表中的所有项目转换为字符串。比如说

-调试:
msg:“{{findname in MyDict”|
映射(attribute='name')|
映射('字符串')|
列表}”

还要转换变量
findname
,以确保始终比较stings

-调试:
msg:“{findname | MyDict中的字符串|
映射(attribute='name')|
映射('字符串')|
列表}”

在循环中测试它。比如说

-调试:
msg:{{item}MyList中的字符串}”
循环:
-鲍勃
- 101
- "101"
-乔
变量:
MyList:“{{MyDict|
映射(attribute='name')|
映射('字符串')|
列表}”
给予

ok:[localhost]=>(item=Bob)=>{
“msg”:正确
}
确定:[localhost]=>(项=101)=>{
“msg”:正确
}
确定:[localhost]=>(项=101)=>{
“msg”:正确
}
确定:[localhost]=>(item=Joe)=>{
“msg”:错误
}

真诚的道歉。我刚注意到我在开始的问题上打错了。我写道“有没有一种方法可以让查找将列表中的值转换为整数?”。我的意思是“字符串”而不是整数。我现在已经更正了问题。非常感谢!我已经测试并添加了map('string'),这正是我想要的。感谢您提供有关将findname转换为字符串的额外提示。:)