I'm writing an ansible playbook to automate the installation of a piece of software. When I download the tarball from the website I have:
software-package-release.tar.gz
When untarred I'm left with the directory
software-package-v2.15/
Does ansible have any way of registering the directory created as part of the unarchive module?
I've tried with the following plays (I put the nrpe-lkdsflkdjf
file there which contains a dir 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
And this was the output of the debug:
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
}
}
The unarchive module does have the option to list the files - list_files
. The output can be registered, and usually the first value in the array is the directory name.
The following worked for me:
- 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]
will have your top level directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With