我正在编写一个简单的剧本,通过使用SNOW_record_find模块来获取SNOW记录。文件(https://docs.ansible.com/ansible/latest/modules/snow_record_find_module.html)有非常有限的例子。
除此之外,我也无法准确理解api文档(https://pysnow.readthedocs.io/en/latest/api/query_builder.html)。
我试过这个游戏:
- name: Find records in sc_item_option list
snow_record_find:
username: username
password: password
instance: instance
table: sc_item_option
query:
sys_id:
IN:
- "5203930cdb230010a5d39235ca9619f6"
- "605d12bedbe70010a5d39235ca9619dd"
- "81115fc8db230010a5d39235ca96193d"
register: allVarsRecord
并得到这个错误:
Expected value of type `str` or `list`, not <class 'dict'>", "query": {"sys_id": {"IN": ["5203930cdb230010a5d39235ca9619f6", "605d12bedbe70010a5d39235ca9619dd", "81115fc8db230010a5d39235ca96193d"]}}
我还修改了我的战术手册如下:
- name: Find records in sc_item_option list
snow_record_find:
username: username
password: password
instance: instance
table: sc_item_option
query:
IN:
sys_id:
- "5203930cdb230010a5d39235ca9619f6"
- "605d12bedbe70010a5d39235ca9619dd"
- "81115fc8db230010a5d39235ca96193d"
register: allVarsRecord
- debug:
msg: "{{allVarsRecord}}"
然后得到这个错误:
Expected value of type `str` or `list`, not <class 'dict'>", "query": {"IN": {"sys_id": ["5203930cdb230010a5d39235ca9619f6", "605d12bedbe70010a5d39235ca9619dd", "81115fc8db230010a5d39235ca96193d"]}}
如何解决此错误并使其工作?任何建议都可以,因为我已经筋疲力尽了。。
提前谢谢。
使用equals
而不是IN
,根据值的不同,雪查询生成器将添加IN
(如果是列表(或=
(如果是字符串(条件。
- name: Find records in sc_item_option list
snow_record_find:
username: username
password: password
instance: instance
table: sc_item_option
query:
equals:
sys_id:
- "5203930cdb230010a5d39235ca9619f6"
- "605d12bedbe70010a5d39235ca9619dd"
- "81115fc8db230010a5d39235ca96193d"
register: allVarsRecord
PS:未测试。基于查询生成器文档创建。
感谢franklinsijo的回答。当ansible看到列表时,"IN"会自动应用,只需使用标准的equals即可。但对于这种情况,由于它是单个查询,因此也不需要"equals"操作,否则我仍然会得到预期的"str"one_answers"list"错误。行动手册如下所示:
- name: Find records in sc_item_option list
snow_record_find:
username: username
password: password
instance: instance
table: sc_item_option
query:
sys_id:
- "5203930cdb230010a5d39235ca9619f6"
- "605d12bedbe70010a5d39235ca9619dd"
- "81115fc8db230010a5d39235ca96193d"
register: allVarsRecord