ansible剧本无法继续执行,因为我们读取文件时由于文件更改而导致tar失败 [英] ansible playbook unable to continue as the `tar` fails due to `file change as we read`

查看:274
本文介绍了ansible剧本无法继续执行,因为我们读取文件时由于文件更改而导致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

上面给出了以下错误.

警告":使用非归档模块而不是运行tar stderr: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不给模块提供tar代码.只有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剧本无法继续执行,因为我们读取文件时由于文件更改而导致tar失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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