我正在下载一个非常大的视频文件,其下载百分比通过其他工具存储在 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
最佳答案
关于ansible - 在ansible中执行until循环期间打印输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57100710/