ansible playbook 无法继续,因为“tar"由于“文件更改时我们阅读"而失败 [英] ansible playbook unable to continue as the `tar` fails due to `file change as we read`

查看:38
本文介绍了ansible playbook 无法继续,因为“tar"由于“文件更改时我们阅读"而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 ansible-playbook,它正在运行 tar 命令来压缩一个目录.以下是 ansible 任务.

I am running an ansible-playbook which is doing running tar command to zip a directory. Following is the ansible task.

  - name: tar the old code
    command: tar -czf {{ansible_date_time.date}}.tar.gz /home/ubuntu/my-folder

上面给出了以下错误.

"warnings": 使用 unarchive 模块而不是运行 tarstderr: tar: 从成员名称中删除前导/"tar:/home/ubuntu/my-folder/xyz.log: 文件在我们阅读时发生变化

"warnings": use unarchive module rather than running tar stderr: tar: Removing leading '/' from member names tar: /home/ubuntu/my-folder/xyz.log: file change as we read it

我也尝试使用选项 --ignore-failed-read 但它没有压缩目录但成功运行了其余的任务.

I also tried with option --ignore-failed-read but it didn't zipped the directory but ran the rest of the tasks successfully.

  - name: tar the old code
    command: tar -czf {{ansible_date_time.date}}.tar.gz /home/ubuntu/my-folder  --ignore-failed-read

由于此任务介于其他任务之间,因此此任务失败后必须运行的任务.

Since this task is in between other tasks, the tasks which has to be run after this one fails.

ansible 不提供模块来压缩代码.只有 unarchive 模块可以解压目录.

ansible doesn't give module to tar the code. only unarchive module is there to unzip the directory.

推荐答案

tar 命令在遇到文件在读取时更改"问题时将退出并返回 1关于 Ansible 如何解释这一点的权威太多,我假设它会将任何非零返回码视为失败".我通过告诉 Ansible 重新定义它认为是失败的内容来解决这个问题:

The tar command will exit with a return code of 1 when it experiences the "file change as we read it" problem, and while I can't speak with too much authority as to how Ansible interprets that, I'm assuming it will treat any non-zero return code as "failed." I worked around the issue by telling Ansible to redefine what it considers to be failure:

- name: tar the old code
  command: tar -czf {{ansible_date_time.date}}.tar.gz /home/ubuntu/my-folder
  register: tar_result
  failed_when: tar_result.rc > 1

这篇关于ansible playbook 无法继续,因为“tar"由于“文件更改时我们阅读"而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆