So friends in the previous video we learned how we could use the archive module
to effectively
archive and compress files. Now in this particular video what I want to do is
to highlight to
you how we can effectively unarchive files. So over on my blue box machine I
had deleted all
the individual files all I have right here is the archive file which is being
compressed
with BZ2. Now what I'm going to do here is I will go to my browser once again
and if I happen to search
for Ansible unarchive notice what we actually have here we have an Ansible WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
for Ansible unarchive notice what we actually have here we have an Ansible
built in unarchive
modules. This is actually going to be within the Ansible core collection so we
don't have to do
any type of additional installs. Notice the synopsis actually tells us here
directly that this particular
module is going to unpack an archive it's not going to unpack a compress file
that doesn't contain
an archive okay. Now be aware here this one by default is going to copy the
source file from the
local system to the target before unpacking so that is going to act very
differently from the WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
differently from the
previous module we're actually talking about copying from the local system that
is the Ansible
control node unless if we look below we can specify this parameter here remote_
src which is remote
source we can specify that to the value yes to unpack an archive which already
exists on the target
so if we want to unpack that file that already exists on the blue box we indeed
want to specify
this particular parameter and configure it to have the value of yes. So we can
see a whole
bunch of parameters we have this copy parameter notice though that this WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
bunch of parameters we have this copy parameter notice though that this
particular parameter has
been deprecated and we instead should use the remote_src we just talked about
so just be aware of that
in documentation okay. Again notice we happen to have our desk parameter this
is required this is the
remote absolute path where the archive is going to be unpacked so where do you
want the actual
contents to reside after the unpacking has happened. Scrolling on down once
again we can
specify the mode to configure particular permissions whether that is opton
notation or some ballot
notation and again we can specify the owner just like the previous module and WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
notation and again we can specify the owner just like the previous module and
this time as we can
see here we have remote source with a billion value either set to the value
true or by default as we
can see here the value false. Now notice as well we also have this particular
option here the
src parameter this also is a required parameter and this is where we specify
the value of the
source file pretty much where is the file we want to unpack so again let's go
and take this
information and begin writing our playbook. So back on the Ansible Control mode WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
information and begin writing our playbook. So back on the Ansible Control mode
let's try to play
bit called play2.ymlgreens insert have our three hyphens at the top give this a
name and we'll
just say play2 testing the un-archive module. Next we will specify the hosts
that we want to target
in this case here it's just going to be the blue box once again gather facts
also set to the
billion value of false. Now let's define our tasks and this task can have a
name simply specifying
targeting the archive file to unpack. Now we have a few things that we want to
specify a source
a destination as well as to determine if the source is going to be remote or WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
a destination as well as to determine if the source is going to be remote or
not. Now think
about it what are we trying to unpack well over on the blue box within this
particular directory
we want to unpack this particular file so that is going to be our source. So
let's define that
accordingly via the SRC parameter so it's going to be in home nuggetuser and
the file is called my
archive dot tar dot bz2. Now once again Ansible is going to look for this
particular file on the
control mode we don't want that to happen we want to ensure that it's searching WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
control mode we don't want that to happen we want to ensure that it's searching
for this path on the
remote host okay which is the blue box. So I'm going to set the remote
underscore SRC to the value
of true and now let me specify where it is exactly I want this to be extracted
so let's specify the
desk parameter and this time let's say we're going to target the home nugget
user and let's just try
to put this in let's go with the download directory okay in fact let's actually
change that to the
documents directory that makes a little bit more sense so let's just save this
for now and if WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
for now and if
we just go into the documents directory right now notice we actually don't have
anything inside of
it when we actually extract this particular file into this directory though we
should actually see
the contents of the archive inside of here so let's go and run the playbook and
see if that happens
so let's try to run the playbook hit enter and we haven't have an error let's
go back in and check
and that's because I didn't even attempt to use the module so why didn't you
tell me that okay
you were just letting me be silly there so let's try that entire again this
should be the answer WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
should be the answer
will build in on archive module and I'm just going to end then all this stuff
here okay so let's
knock everything into spaces and let's try that entirely again so arrow up try
again hit enter
this looks a little bit better and as we can see here we now get the result let
's go back and see
what's happened then so slide on over to the blue box let's do an LS or rather
an LS we'll try
and look at what we actually have here the contents of the archive file here
have now been populated
inside of the documents directory on the target device so that is how we can WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
inside of the documents directory on the target device so that is how we can
archive files and
unarchive them notice the process is a little bit different understand how
these different modules
operate particularly with respect to the unarchive module keep aware that we
have to specify explicitly
when the source happens to be a remote machine