monk
monk

Reputation: 2115

Printing output during until loop is executing in ansible

I am performing a download of a very large video file, its download percentage is getting stored in DL_PERCENTAGE file through other tool. Now I am trying to keep the playbook in until loop till 60 percentage of download is done at the same time I need to print the current download percentage in the terminal.

Here is the playbook, I attempted to print the download percentage during the execution, but its always printed zero. It never showed the upgraded values from file DL_PERCENTAGE ?

cat  test.yml
---

- hosts: localhost
  tasks:

   - name: set initial value of progress percentage to zero
     set_fact:
       percentage: 0


   - name: download percentage is  {{ percentage | default("0") }}
     shell: cat DL_PERCENTAGE
     register: percentage
     until: percentage.stdout >= 60
     retries: 5
     delay: 10

Current output:

>ansible-playbook  test.yml


PLAY [localhost] *************************************************************************************************************************************************************************************************************************


TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [set initial value of progress percentage to zero] **********************************************************************************************************************************************************************************
ok: [localhost]

TASK [download percentage is  0] *********************************************************************************************************************************************************************************************************
FAILED - RETRYING: download percentage is  0 (5 retries left).
FAILED - RETRYING: download percentage is  0 (4 retries left).
FAILED - RETRYING: download percentage is  0 (3 retries left).
FAILED - RETRYING: download percentage is  0 (2 retries left).
FAILED - RETRYING: download percentage is  0 (1 retries left).

I am trying to get following output, based on the updated contents of DL_PERCENTAGE file:

>ansible-playbook  test.yml


PLAY [localhost] *************************************************************************************************************************************************************************************************************************


TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [set initial value of progress percentage to zero] **********************************************************************************************************************************************************************************
ok: [localhost]

TASK [download percentage is  0] *********************************************************************************************************************************************************************************************************
FAILED - RETRYING: download percentage is  0 (5 retries left).
FAILED - RETRYING: download percentage is  23 (4 retries left).
FAILED - RETRYING: download percentage is  45 (3 retries left).
FAILED - RETRYING: download percentage is  49 (2 retries left).
FAILED - RETRYING: download percentage is  53(1 retries left).

Following is example showing change in file contents with time:

cat DL_PERCENTAGE
0
sleep 5;
cat DL_PERCENTAGE
11
sleep 5;
cat DL_PERCENTAGE
21

Upvotes: 2

Views: 1952

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68074

It is not possible. See Feature: Allow until-loops on blocks or includes #46203.

Upvotes: 3

Related Questions