我正在运行一个ansible-playbook
它正在运行tar
命令来压缩目录。以下是ansible
任务。
- 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:我们阅读时的文件更改
我也尝试使用选项 --ignore-failed-read
但它没有压缩目录,但成功运行了其余任务。
- name: tar the old code
command: tar -czf {{ansible_date_time.date}}.tar.gz /home/ubuntu/my-folder --ignore-failed-read
由于此任务位于其他任务之间,因此在此任务之后必须运行的任务将失败。
Ansible 没有提供模块来 tar 代码。 只有unarchive
模块可以解压缩目录。
tar 命令在遇到"我们读取文件时更改"问题时将以返回代码 1 退出,虽然我不能过多地谈论 Ansible 如何解释它,但我假设它会将任何非零返回代码视为"失败"。 我通过告诉 Ansible 重新定义它认为的失败来解决这个问题:
- 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