在ansible中执行直到作业循环期间的打印输出

时间:2019-07-18 18:32:24

标签: ansible

我正在下载一个非常大的视频文件,它的下载百分比正在通过其他工具存储在DL_PERCENTAGE文件中。现在,我尝试将剧本保留到循环播放,直到完成60%的下载,同时我需要在终端中打印当前的下载百分比。

这是剧本,我尝试在执行过程中打印下载百分比,但始终打印为零。它从未显示过文件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

当前输出:

>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).

基于DL_PERCENTAGE文件的更新内容,我试图获得以下输出:

>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).

以下是显示文件内容随时间变化的示例:

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

1 个答案:

答案 0 :(得分:2)