On Wed, 29 Apr 2020 01:52:47 -0700 (PDT)
Ivo Hechmann <[email protected]> wrote:

> ansible should retry the command, lets say 5 tries:
> 
> - name: process something, fail if not 5 files in tmpdir
>   shell: "/home/ivo/workspace/splunk-envs/scripts/retry/run.sh"
>   ignore_errors: True
>   register: status_var
>   until: status_var is not failed
>   delay: 1
>   retries: 4
> 
> ... how can I pass the retry number to the run.sh? 
> ... there is some loop_control and 
> ansible_loop_index, but i cannot combine these variables with the shell 
> command in an until-loop. Is there a syntax problem or some better
> way the achieve my goal?

IMHO, neither "shell" nor "loop_control" will make it. The runstring in
"shell" will be evaluated only once when the module starts. The
"loop_control" looks promising, but there is no option how to break a "loop"
in Ansible.

The best option would be to pass a variable, for example "number_of
retries" both to the script and to the module, and let the script make the
counting on its own. For example,

  - name: process something, fail if not 5 files in tmpdir
    command: "run.sh {{ number_of_retries }}"
    ...
    retries: "{{ number_of)retries }}"

HTH,

        -vlado

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200429123045.60b3df52%40gmail.com.

Attachment: pgpTUDnpDGu19.pgp
Description: OpenPGP digital signature

Reply via email to