gpt4 book ai didi

ansible - 如何判断 ansible unarchive 模块创建了哪个目录?

转载 作者:行者123 更新时间:2023-12-04 00:30:17 25 4
gpt4 key购买 nike

我正在编写一个 ansible playbook 来自动安装一个软件。当我从网站下载压缩包时,我有:

software-package-release.tar.gz

解压后,我只剩下目录
software-package-v2.15/

ansible 是否有任何方法可以注册作为 unarchive 模块的一部分创建的目录?

我已经尝试过以下播放(我将 nrpe-lkdsflkdjf 文件放在那里,其中包含一个目录 nrpe-2.15 )
- name: Extract
unarchive
src:/tmp/nrpe-lkdsflkdjf
dest: /tmp/
copy: no
register: tar_reg

- name: debug tar_reg
debug: var=tar_reg

这是调试的输出:
ok: [IP-here] => {
"tar_reg": {
"changed": true,
"check_results": {
"cmd": "/bin/gtar -C \"/tmp/\" --diff -f \"/tmp/nrpe-lkdsjflkdsjf\"",
"err": "/bin/gtar: nrpe-2.15: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/SECURITY: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/README.Solaris: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/init-script.debian.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/nrpe.spec.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/LEGAL: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/subst.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/sample-config: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/sample-config/nrpe.xinetd.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/sample-config/nrpe.cfg.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/preinstall: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/nrpe.xml: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/i.config: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/postinstall: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/r.config: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/pkg/nrpe: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/package/solaris/Makefile.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/nrpe.spec: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/README: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/acl.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/check_nrpe.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/snprintf.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/Makefile.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/utils.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/src/nrpe.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/config.guess: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/install-sh: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/contrib: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/contrib/nrpe_check_control.c: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/contrib/README.nrpe_check_control: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/init-script.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/docs: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/docs/NRPE.pdf: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/docs/NRPE.odt: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/init-script.suse.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/configure: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/config.sub: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/Changelog: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/Makefile.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/README.SSL: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/configure.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/update-version: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/dh.h: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/common.h: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/utils.h: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/acl.h: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/config.h.in: Warning: Cannot stat: No such file or directory\n/bin/gtar: nrpe-2.15/include/nrpe.h: Warning: Cannot stat: No such file or directory\n",
"out": "",
"rc": 1,
"unarchived": false
},
"dest": "/tmp/",
"extract_results": {
"cmd": "/bin/gtar -xf \"/tmp/nrpe-lkdsjflkdsjf\"",
"err": "",
"out": "",
"rc": 0
},
"gid": 0,
"group": "root",
"handler": "TarArchive",
"mode": "01777",
"owner": "root",
"size": 3072,
"src": "/tmp/nrpe-lkdsjflkdsjf",
"state": "directory",
"uid": 0
}
}

最佳答案

unarchive module确实有列出文件的选项 - list_files .可以注册输出,通常数组中的第一个值是目录名。

以下对我有用:

- name: Extract files
unarchive:
src: /tmp/my_archive.tar.gz
dest: /mydir
remote_src: yes
list_files: yes
register: archive_contents
archive_contents.files[0]将有您的顶级目录。

关于ansible - 如何判断 ansible unarchive 模块创建了哪个目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37576449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com