I need to search a string "TicketID" in .db files under a directory. If 
found my playbook should fail.


Below is my playbook for the same, however I'm getting runtime error "using 
with_items"

Output:

> TASK [Search for Number] 
> *************************************************************************************************************
>  
> fatal: [45.72.65.99]: FAILED! => {"msg": "obj must be a list of dicts or a 
> nested dict"}


Below is my ansible playbook's task:


   - name: find multiple .db files under a given location
     find:
       paths: "{{ BASEPATH }}"
       patterns: "*.db"
       recurse: yes
     register: files_matched

   - name: "Search for Number
     command: "grep -i {{ TicketID }} {{ item.path }}"
     register: command_result
     failed_when: command_result.rc == 0
     with_items:
      - "{{ files_matched.files }}"



I tried using loop instead of with_items as below but that too did not work


   - name: "Search for Number
     command: "grep -i {{ TicketID }} {{ item.1.path }}"
     register: command_result
     failed_when: command_result.rc == 0
     loop: "{{ files_matched.results | subelements('files') }}"



Output:

> TASK [Search for Number] 
> *************************************************************************************************************
> fatal: [45.72.65.99]: FAILED! => {"msg": "obj must be a list of dicts or a 
> nested dict"}


I also tried using json_query  like below but I still get error:


   - name: "Search for Number"
     command: "grep -i {{ TicketID }} {{ item }}"
     register: command_result
     failed_when: command_result.rc == 0
     loop: "{{ files_matched.files|json_query('[].path') }}"



Output:

> TASK [Search for Number] 
> *************************************************************************************************************
> fatal: [45.72.65.99]: FAILED! => {"msg": "Invalid data passed to 'loop', 
> it requires a list, got this instead: . Hint: If you passed a list/dict of 
> just one element, try adding wantlist=True to your lookup invocation or use 
> q/query instead of lookup."}


I would like to understand why is this playbook failing and how I can fix 
it.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6b0c5faa-b14a-43a5-9030-4425ea3ebf37%40googlegroups.com.

Reply via email to