ansible playbook unable to continue as the `tar` fails due to `file change as we read`

泪湿孤枕 提交于 2019-12-10 22:34:20

问题


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

The above gives the following error.

"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

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 doesn't give module to tar the code. only unarchive module is there to unzip the directory.


回答1:


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


来源:https://stackoverflow.com/questions/35023608/ansible-playbook-unable-to-continue-as-the-tar-fails-due-to-file-change-as-we

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!