4

I am working on ansible playbook to grab SNOW record by using snow_record_find module. The documentation (https://docs.ansible.com/ansible/latest/modules/snow_record_find_module.html) have very limited example.

Besides that, I am also unable to understand accurately the api docs (https://pysnow.readthedocs.io/en/latest/api/query_builder.html).

I have tried this play:

    - 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

and get this error:

Expected value of type `str` or `list`, not <class 'dict'>", "query": {"sys_id": {"IN": ["5203930cdb230010a5d39235ca9619f6", "605d12bedbe70010a5d39235ca9619dd", "81115fc8db230010a5d39235ca96193d"]}}

I have also have revised my playbook to be like this:

    - 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}}"

and then get this error:

Expected value of type `str` or `list`, not <class 'dict'>", "query": {"IN": {"sys_id": ["5203930cdb230010a5d39235ca9619f6", "605d12bedbe70010a5d39235ca9619dd", "81115fc8db230010a5d39235ca96193d"]}}

How can I resolve this error and make this work? Any suggestion will do as my mind is exhausted already to think on this..

Thanks in advance.

Fitri Izuan
  • 350
  • 1
  • 6
  • 18

2 Answers2

2

Use equals instead of IN, depending on the value, the snow query builder will add IN (if list) or = (if string) condition.

    - 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: Untested. Created based on the query builder documentation.

franklinsijo
  • 17,784
  • 4
  • 45
  • 63
  • 1
    Hi, thank you for ur answer. So that is what it means in the api docs. however, I still get the expected 'str' and 'list' error. But I managed to resolve it based on ur answer. The playbook is at other comment. thanks. – Fitri Izuan Apr 14 '20 at 01:41
0

Thanks for the answer given by franklinsijo. The 'IN' automatically applied when ansible see the list, just do it by using standard equals. But for this case, since it is single query, then it is also does not need the 'equals' operation, else I still get the expected 'str' and 'list' error. the playbook is as shown below:

    - 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
Fitri Izuan
  • 350
  • 1
  • 6
  • 18