> On 16. Feb 2021, at 08:24, Mukuntha rajaa <mukunthara...@gmail.com> wrote:
> 
> Hello,
> 
> I am using custom module and looping through items to do "kubectl apply -f". 
> 
> - name: create rbac objects
>   kubectl:
>     manifest: "{{ item }}"
>     state: present
>   with_fileglob: "{{ CAAS.rbac_manifests_directory }}/*"
>   register: rbacresult
>   failed_when: '"v1beta1 is deprecated" not in rbacresult.results[0].stdout'
>   tags: rbac
> 
> Here it fails with, 
> 
> fatal: [localhost]: FAILED! => {"msg": "The conditional check 'v1beta1 not in 
> rbacresult.results[0].stdout' failed. The error was: error while evaluating 
> conditional (v1beta1 not in rbacresult.results[0].stdout): Unable to look up 
> a name or access an attribute in template string ({% if v1beta1 not in 
> rbacresult.results[0].stdout %} True {% else %} False {% endif %}).\nMake 
> sure your variable name does not contain invalid characters like '-': 
> argument of type 'AnsibleUndefined' is not iterable"}
> 
> It would be nice, if I could loop through complete result variable and then 
> fail only if "not of my specific-condition".


At the level of a single item the `results` array for all items
is not yet available.  The whole array will only be available
after the task has finished looping over all items.  So you will
have to check for `… not in rbacresult.stdout` in the above case.

This minimal example should illustrate the effect:

```
- hosts: localhost
  tasks:
    - name: Dummy
      shell:
        cmd: echo {{ item }}
      with_items:
        - "positive"
        - "negative"
      register: result
      failed_when: '"positive" not in result.stdout'
      ignore_errors: yes

    - name: Debug
      debug:
        var: result

```

-Andi

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/5A9EE0F2-8667-4A72-942F-A74F7019B770%40gmail.com.

Reply via email to