cancel
Showing results for 
Search instead for 
Did you mean: 
Ad_astra
Flight Engineer Flight Engineer
Flight Engineer
  • 1,894 Views

Ansible modules for working with tar files

Jump to solution

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 

Labels (1)
2 Solutions

Accepted Solutions
bonnevil
Starfighter Starfighter
Starfighter
  • 1,879 Views

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.

View solution in original post

bonnevil
Starfighter Starfighter
Starfighter
  • 1,848 Views

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.

View solution in original post

5 Replies
bonnevil
Starfighter Starfighter
Starfighter
  • 1,880 Views

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.

wbialy
Flight Engineer Flight Engineer
Flight Engineer
  • 1,875 Views

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/

Ad_astra
Flight Engineer Flight Engineer
Flight Engineer
  • 1,866 Views

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 

0 Kudos
bonnevil
Starfighter Starfighter
Starfighter
  • 1,849 Views

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.

Ad_astra
Flight Engineer Flight Engineer
Flight Engineer
  • 1,765 Views

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

0 Kudos
Join the discussion
You must log in to join this conversation.