[英]Ansible Playbook - Pysnow: Find record using 'IN' clause query
我正在編寫 ansible 劇本,使用 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
,根據值,snow 查詢構建器將添加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'操作,否則我仍然會得到預期的'str'和'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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.