ansible can';t unarchive tar.gz文件
我正试图用ansible(我已经做了很多)解压tar.gz文件,但由于某些原因,这次我无法避免这个错误 我不断得到:ansible can';t unarchive tar.gz文件,ansible,Ansible,我正试图用ansible(我已经做了很多)解压tar.gz文件,但由于某些原因,这次我无法避免这个错误 我不断得到: "msg": "Failed to find handler for \"/tmp/ansible_mnXJGp/internalbuildscripts1.tar.gz\". Make sure the required command to extract the file is installed. Command \"/bin/tar\" could not handle
"msg": "Failed to find handler for \"/tmp/ansible_mnXJGp/internalbuildscripts1.tar.gz\". Make sure the required command to extract the file is installed. Command \"/bin/tar\" could not handle archive. Command \"/usr/bin/unzip\" could not handle archive."
奇怪的是,它似乎试图在tar.gz文件上使用解压
任务如下所示:
- name: Download build scripts
unarchive:
src: https://sblah.com/internalbuildscripts1.tar.gz
dest: /home/xxxx/buildscripts
remote_src: yes
因此,我遇到了同样的问题,并最终调试了unarchive模块,以找出它认为无法处理该文件的原因 TL;DR My
dest
是一条相对路径。unarchive
对检查gtar
是否会处理该文件所做的检查如下:
/usr/local/bin/gtar --list -C ./my/dest/path -z -f /Users/fransf/.ansible/tmp/ansible-tmp-1603283396.0748851-45418-232955281061540/source
但它这样做时,工作目录也被设置为/my/dest/path
,因此它实际上是在尝试解压到不存在的/my/dest/path/my/dest/path强>
这就是我的问题所在。我改为使用绝对路径,unarchive
很高兴。我确实认为这是一个bug,而且显然是一个测试用例,它还不在非归档测试套件中
Ansible模块的调试
将环境变量设置为1
(即ANSIBLE\u KEEP\u REMOTE\u FILES=1 ANSIBLE playbook-vvvv deploy.yml
)运行您的playbook。在输出的某个地方(如果您使用-vvvv
运行),您将看到如下内容:
EXEC /bin/sh -c '/usr/local/Cellar/ansible/2.9.10/libexec/bin/python3.8 /Users/fransf/.ansible/tmp/ansible-tmp-1603283396.0748851-45418-232955281061540/AnsiballZ_unarchive.py && sleep 0'
运行相同的命令,但使用explode
参数,如下所示:
/usr/local/Cellar/ansible/2.9.10/libexec/bin/python3.8 /Users/fransf/.ansible/tmp/ansible-tmp-1603283396.0748851-45418-232955281061540/AnsiballZ_unarchive.py explode
您将得到一些输出,告诉您分解的模块源写入的位置,例如
2955281061540/AnsiballZ_unarchive.py explode
Module expanded into:
/Users/fransf/.ansible/tmp/ansible-tmp-1603283396.0748851-45418232955281061540/debug_dir
现在您已经获得了Python源代码,您可以使用print
语句或(这就是我所做的)运行实际的调试器。要运行模块,请使用与分解相同的命令,但指定execute
而不是explode
:
/usr/local/Cellar/ansible/2.9.10/libexec/bin/python3.8 /Users/fransf/.ansible/tmp/ansible-tmp-1603283396.0748851-45418-232955281061540/AnsiballZ_unarchive.py execute
您可以从命令行或IDE执行此操作。我已经在使用IntelliJ Ultimate,安装Python插件就是我所需要的,这样我就可以通过调试器运行这个模块,设置断点,查看变量,并找出哪里出了问题
希望这能帮助其他人解决类似的问题。在远程主机上获得了gunzip
?是的。.在目标主机上获得了file/bin/tar
的输出是什么?它向我显示了:/bin/tar:ELF 64位LSB共享对象,x86-64,版本1(SYSV),动态链接,解释器/lib64/ld-linux-x86-64。so.2,对于GNU/Linux 2.6.32,BuildID[sha1]=8c0aa0b931333b10dd5a86a09f05b6626ffa944e,剥离的
我实际上从未设法使非归档的
工作。我觉得他们在这个模块上有点超前了。我建议使用synchronize
(基本上是rsync)来复制文件,然后使用shell
并再次收集所有tar
标志。。。