On Wednesday, September 11, 2019 at 3:57:30 PM UTC-4, Vladimir Botka wrote:
>
> On Wed, 11 Sep 2019 18:02:08 +0530 
> Kamesh Sampath <ksam...@redhat.com <javascript:>> wrote: 
>
> > > >>   set_fact: 
> > > >>     che_keycloak: 
> > > >> "{{ lookup('k8s', 
> > > >> api_version='route.openshift.io/v1',kind='Route',resource_name='keycloak',namespace='che')
> > > >>  
>   
> > > >> }}" 
> > > >>   register: che_keycloak_route_result 
> > > >>   until: che_keycloak.spec is defined 
> > > >>   retries: 30 
> > > >>   delay: 10 
> > > >>   when: state == 'present' 
> > > 
> > > With set_fact and until it will not set the variable on each iteration 
> > > unfortunately.   
> > 
> > That is what I observe :( 
> > 
> > > I don't know of any workaround.   
> > 
> > any other better way you think of doing my task? 
>
> The "lookup" plugin is evaluated only once before the module starts [1]. 
> Hence it's not possible to get it working with the until/retries 
> construct. 
>
> FWIW, it is possible to put it together. The "brute-force" playbook below 
>
>       - hosts: localhost 
>         vars: 
>           my_continue: true 
>           my_delay: 10 
>           my_retries: 5 
>         tasks: 
>           - include_tasks: include-lookup.yml 
>             loop: "{{ range(0, my_retries)|list }}" 
>
> with the included file include-lookup.yml 
>
>       - name: 'Get data' 
>         set_fact: 
>           my_var: "{{ lookup('pipe', '/scratch/tmp/my_script')|from_yaml 
> }}" 
>         when: my_continue 
>       - name: 'Set continue=false when data OK' 
>         set_fact: 
>           my_continue: false 
>         when: 
>           - my_var.spec is defined 
>           - my_continue 
>       - name: 'Delay next iteration' 
>         wait_for: 
>           timeout: "{{ my_delay }}" 
>         when: my_continue 
>
> does the job. The concept works. When the variable "my_var.spec" is 
> defined 
> then the variable "continue" will be set to False and following tasks will 
> be 
> skipped. 
>
 
That seems overly complex. I would instead wait until the required data is 
available before running set_fact:

- vars:
    che_keycloak_lookup: "{{ lookup('k8s', 
api_version='route.openshift.io/v1',kind='Route',resource='keycloak',namespace='che')
 
}}"
  block:
    - debug:
        msg: Waiting for data propagation...
      until: "'spec' in che_keycloak_lookup"
      retries: 30
      delay: 10

    - name: Get Che Keycloak facts
      set_fact:
        che_keycloak: "{{ che_keycloak_lookup }}"


-- 
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/e960f34e-22ab-4677-bb75-aaefa6012b7e%40googlegroups.com.

Reply via email to