What is Ansible untar?

What is Ansible untar?
Techiio-author
Written by Nilima PaulFebruary 7, 2022
10 min read
Ansible
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

We will know in this article, what's the Ansible untar.

Introduction to Ansible untar

Ansible untar module otherwise called unarchive for Unix OS or win_zip for the windows working framework is utilized to extricate or unload the document records or envelopes on the far off objective by replicating the chronicle record first as a matter of course on the distant server and furthermore upholds numerous boundaries to manage the unarchive or win_zip usefulness like the proprietor, dest, bar from there, the sky is the limit.

Syntax

For the non-windows target unarchive or ansible.builtin.unarchive command uses the below syntax. We have shown the basics parameters

  • Parameters:

copy: No / Yes (Default)

The default Option is Yes and it copies the files from the local controller to the remote host if specified yes or nothing specified. For working with the remote source need to specify the remote_src and this copy parameter is not helpful there.

  • src (required):

Source path of the file. If remote_src is ‘yes’ then the source path would be on the remote location otherwise the source path is on the local controller node.

  • dest (required):

Remote server absolute path where the archive is going to extract.

remote_src: no (Default) / yes

If set ‘yes’ specifies that the source archive path is on the remote computer. For the ‘no’ value the path is on the local controller node.

  • owner:

name of the user that should own the files/directory after unpack and same replicates (added) to the chown.

  • group:

Name of the group that should own the files/directory and same replicates (added) to the chown.

  • exclude:

List of files or directories that need to be excluded from the unpacking.

  • include:

List of files or directories that need to be included in the unpacking process.

keep_newer: no (default) / yes

If set yes, it replaces the existing files that are newer than the files inside the archive.

  • mode:

Permissions that the files or directories should have after unpacked (like 644, 777, etc).

There are other additional parameters like creates, seuser, serole, setype, selevel, unsafe_writes, validate_certs.

For the windows target src, dest, creates parameters remain the same as unarchive module and the additional parameters are as below.

  • Parameters:

delete_archive: no (default) / yes

Removes the zip file after unzipping.

password

If the Zip file is password encrypted then this parameter is useful and it requires the PSCX module to be installed.

recurse: no (default) / yes

recursively expands the zip file within the src directory.

Setting value ‘yes’ requires the PSCX module to be installed.

Please note: the win_unzip module doesn’t use the remote_src parameter.

How untar works in Ansible?

Ansible unarchive module for non-windows target accompanies the ansible-base thus it is remembered for the Ansible establishments. For the windows target, we want to utilize the win_unzip module. On the off chance that the module isn't accessible then you can download it from the world.

ansible-galaxy collection install community.windows

Below is the simple playbook for windows untar (unzip).

---
- name: Ansible playbook for windows unzip module
hosts: winservers
tasks:
- name: Unzip the file from the remote location
win_unzip:
src: \\ad\shared\7zipModule.zip
dest: c:\temp\7zipInstaller

Output:

blogpost

The above playbook will unfasten the record from the source area to the objective distant servers. On the off chance that the objective way doesn't exist it makes the objective way.

You more likely than not saw here, albeit the source way is remote, we don't have to utilize remote_src on the grounds that the win_unzip module doesn't uphold it and when we utilize the remote source way for the non-target windows server we should determine the remote_src. For instance,

tasks:
- name: unarchive for from the remote source on the non-windows target
win_unzip:
src: /tmp/myfiles/7zipmodule.tar.gz
dest: /tmp/7zipmodule
remote_src: yes

Examples

Here are the following examples mention below

Example #1 – unarchive module task for UNIX os.

Code:

---
- name: Ansible playbook to unarchive the files on the remote nodes.
hosts: linuxservers
tasks:
- name: Extract the archive file on the remote node
unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar.gz
dest: /tmp/phyes

In this playbook, it will recover the .tar.gz document to the objective remote host/tmp/phyes. Prior to running this task dissimilar to the win_unzip module, you really want to ensure that the objective way exists if not it will toss a blunder.

Output:

blogpost

Example #2 – Exclude files from the archive.

To exclude the certain file from the unpacking we can use h

Code:

---
- name: Ansible playbook to unarchive the files on the remote nodes.
hosts: linuxservers
tasks:
- name: Extract the archive file with exluding text document
unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar
dest: /tmp/phyes
exclude: 'Test1 document.txt'

If there are multiple files to exclude then you can provide the list as below.

unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar
dest: /tmp/phyes
exclude:
- 'Test1 document.txt'
- 'Test2 document.txt'
- 'sourcefile.py'

Example #3 – Include files from the archive

Please note: To use the include parameter, we need ansible.builtin version 2.11.

Code:

tasks:
- name: Extract the archive file with including text document
unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar
dest: /tmp/phyes
include: 'Test1 document.txt'

The above playbook will include only the test1 text file and to include the multiple documents, use the below command.

unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar
dest: /tmp/phyes
include:
- 'Test1 document.txt'
- 'Test2 document.txt'
- 'sourcefile.py'

Example #4 – using multiple parameters together.

Code:

---
- name: Ansible playbook to unarchive the files on the remote nodes.
hosts: linuxservers
tasks:
- name: Extract the archive file with including text document
unarchive:
src: /etc/installers/phayes-geoPHP-1.2-20-g6855624.tar
dest: /tmp/phyes
include:
- 'Test1 document.txt'
- 'Test2 document.txt'
keep_newer: no
mode: 0644
remote_src: yes
owner: ansibleadmin

Conclusion

Untar or unarchive or unfasten modules are extremely helpful when we compose the playbook. It makes it simpler to separate the documents or envelopes on the objective server without utilizing any outsider programming and what's more, it utilizes different boundaries as we don't have to duplicate the record prior to extricating, adding consents after remove, and so on

Ansible
Ansibleuntar
ansib facts
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Nilima Paul
Technology Security Analyst
Techiio-followerTechiio-followerTechiio-follower
201 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance