Hello
Does anyone know if there is an ansible module for creating tar files?
ansible.builtin.unarchive can handle the extraction of tar files, but within the ansible.builtin modules I cannot find anything that allows you to create a tar file. I'm assuming you have to use ansible.builtin.command or ansible.builtin.shell modules to run the tar command 'manually'.
I understand that there may be 3rd party of community modules for tarring files, but wondered if any existed within the core modules.
Thanks
Given that the archive module in Ansible 2.9 got moved to community.general.archive when the Ansible Content Collections were organized, I doubt there's anything in the set supported in Ansible Automation Platform, but I don't know for sure. Usually, if something ended up in the catch-all community.general collection, that means that a more organized group didn't adopt it for support immediately.
I don't know for certain, it'd make sense to take a look with ansible-navigator doc at the supported execution environment's modules and on automation hub to see if there's anything in a supported Ansible Content Collection that might be useful.
Right. In that case, your best bet might be to mess with the ansible.builtin.command module, but it's not a naturally idempotent module so you'll have to be careful about situations where it's already been run once and the tar archive might already exist and so on. There are ways you could handle that, but it requires a bit more careful thought. The module's creates argument could be useful, or you can do things with timestamps or other variables and conditional execution to avoid clobbering an existing archive, appending files to an existing archive when you don't want to (you could get a mix of old and new files in the archive that way), and so on.
Given that the archive module in Ansible 2.9 got moved to community.general.archive when the Ansible Content Collections were organized, I doubt there's anything in the set supported in Ansible Automation Platform, but I don't know for sure. Usually, if something ended up in the catch-all community.general collection, that means that a more organized group didn't adopt it for support immediately.
I don't know for certain, it'd make sense to take a look with ansible-navigator doc at the supported execution environment's modules and on automation hub to see if there's anything in a supported Ansible Content Collection that might be useful.
I belive you should be able to use the community.general.archive module mentioned in the previous response. It has tar as supported type.
https://galaxy.ansible.com/ui/repo/published/community/general/content/module/archive/
Hello
Thank you for your replies.
I am currently learning Ansible using RH294 which has a limited set of modules.
Whilst the community collections may have the tar module, I am guessing I won't have access to these during my exam, so was looking for alternatives.
Thanks
Right. In that case, your best bet might be to mess with the ansible.builtin.command module, but it's not a naturally idempotent module so you'll have to be careful about situations where it's already been run once and the tar archive might already exist and so on. There are ways you could handle that, but it requires a bit more careful thought. The module's creates argument could be useful, or you can do things with timestamps or other variables and conditional execution to avoid clobbering an existing archive, appending files to an existing archive when you don't want to (you could get a mix of old and new files in the archive that way), and so on.
Hello
Thanks for your answer; it matches what I have managed to do! So far, I have used the command and shell modules to get some resutls with tar files.
I have accepted your answer as the solution to this problem (at least in the context of trying to achieve results without additional modules!).
Many thanks
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.