ansible - 在ansible中执行until循环期间打印输出

标签 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

最佳答案

关于ansible - 在ansible中执行until循环期间打印输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57100710/

相关文章:

variables - Ansible block 变量

ansible - 如何将主机添加到 Ansible Tower 库存中的组?

Ansible Unarchive 命令导致错误 "Failed to find handler"

ansible - 如何在不标记的情况下跳过所有角色并运行所有任务

ubuntu - 使用 Ansible 将安全组添加到正在运行的实例

docker - 使用 Ansible 复制 SSL 证书

bash - ansible wget 然后 exec scripts => get_url 等效

ansible - 扩展ansible角色?

yaml - 如何让 Ansible YAML 解析接受这个命令?

if-statement - ansible 变量中的条件文本