# trying to write a tar module/action\_plugin

**URL:** <https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686>\
**Category:** Ansible Project\
**Created:** [October 15, 2013, 7:20pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686 "2013-10-15T19:20:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dylan\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dylan\_Martin](https://forum.ansible.com/u/Dylan_Martin)\
**Post date:** [October 15, 2013, 7:20pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/1 "2013-10-15T19:20:45Z")

</div>

Hi all. I sometimes like to copy tarfiles to hosts and unpack them with ansible. It’s getting a little unwieldy so I thought I’d try to write a module to do it so I could just specify a task like

tar: src=foo.tgz dest=/var/lib/foo

and be done with it

After much confusion and reading of the source, It appears that I’d want to write both a module and an action plugin. The action plugin would copy the tar file from my server to the host being managed and the module would unpack it once there.

Am I right about that?

Can I call another action plugin from my action plugin? IE can I call the copy action plugin to transfer the files? Or is there another way I can re-use that code?

I know a lot of folks do rsync from a local\_action to handle things like this, but I want to know when things are changed or not. I want those pretty little OK and Changed columns in my ansible-playbook output. If I change one file in a collection of static files, I want to know that change made it to each host.

Maybe a better idea is just to write a module that unpacks tar files on the destination host and relies on me using the copy action before hand. Less cool, but a lot easier to develop.

Any suggestions welcome.

Thanks!

-Dylan

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 15, 2013, 7:49pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/2 "2013-10-15T19:49:51Z")

</div>

you can look at the new synchronize plugin waiting to be merged (rsync) which also uses a action\_plugin

---

<div class="post-metadata">

**Author:** ![Dylan\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dylan\_Martin](https://forum.ansible.com/u/Dylan_Martin)\
**Post date:** [October 15, 2013, 8:52pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/3 "2013-10-15T20:52:21Z")

</div>

This may be a dumb question, but where would I find the new synchronize plugin? Or do I wait for it to be merged?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 15, 2013, 9:07pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/4 "2013-10-15T21:07:33Z")

</div>

Normally new/submitted modules appear as pull requests.

this one is at:  
[https://github.com/ansible/ansible/pull/4167](https://github.com/ansible/ansible/pull/4167)

---

<div class="post-metadata">

**Author:** ![Dylan\_Martin1](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Dylan\_Martin1](https://forum.ansible.com/u/Dylan_Martin1)\
**Post date:** [October 15, 2013, 9:12pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/5 "2013-10-15T21:12:20Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [October 15, 2013, 11:39pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/6 "2013-10-15T23:39:07Z")

</div>

The “copy” module is also a good example of a plugin that calls other modules, in this case “file”.

Would be super interested in a module.

we should probably call it “unarchive” maybe?

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [October 16, 2013, 1:09pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/7 "2013-10-16T13:09:33Z")

</div>

One note about the copy-over-and-unarchive-automatically thing: there  
are use cases where one is unarchiving something which was downloaded  
directly to the remote host, and thus it would be useful to support  
purely remote operation also.

---

<div class="post-metadata">

**Author:** ![Jerome\_Wagner](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@Jerome\_Wagner](https://forum.ansible.com/u/Jerome_Wagner)\
**Post date:** [October 16, 2013, 6:16pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/8 "2013-10-16T18:16:04Z")

</div>

Hi,

just a thought, but what would be the best way to ensure idempotency for this unarchive module ?

As I understand it, “unarchive” would :

- transfer a src=\*.tgz to the hosts
- unarchive the file into the dest directory

so how would you check for the similarity of the unarchived src and the previously unarchived content of dest (unarchived in a previous ansible run) ?

---

<div class="post-metadata">

**Author:** ![Dylan\_Martin1](https://avatars.discourse-cdn.com/v4/letter/d/ed655f/32.png) [@Dylan\_Martin1](https://forum.ansible.com/u/Dylan_Martin1)\
**Post date:** [October 16, 2013, 6:54pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/9 "2013-10-16T18:54:03Z")

</div>

I’ve had a couple of ideas:

1. gnu tar (and possibly others) has a --diff option which will compare a tar archive to a directory. This is a bit unwieldy. It doesn’t detect files added to the directory that aren’t in the tarball. Portability depends on how widespread this feature is. (that reminds me, a future feature would be similar to the --delete flag in rsync)

2. One could unpack the tarball into a tmp directory and compare the tmp and dest directories This is inefficient and would fail if the unpacked archive was bigger than the tmp dir. But it does what you want done.

3. Look at any python libs that do tar stuff. If they’re in core python and they support something like --diff in the binary, I’m happy dude. Otherwise, it should be pretty easy to implement a --diff type functionality. If tar in python requires the user to install special libs, that sucks.

4. not checking actually doesn’t violate idempotency - If the destination already matches the tar and you unpack the tar, the destination hasn’t changed. This one is lame because you don’t know when there’s been any changes.

My plan is to start with option 4, which will give me the simplest functional tar module/action\_plugin. Then I’ll try option 3 unless folks suggest otherwise.

---

<div class="post-metadata">

**Author:** ![Dylan\_Martin](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dylan\_Martin](https://forum.ansible.com/u/Dylan_Martin)\
**Post date:** [October 16, 2013, 8:32pm UTC](https://forum.ansible.com/t/trying-to-write-a-tar-module-action-plugin/13686/10 "2013-10-16T20:32:18Z")

</div>

I’ve just finished the barest of bare-bones tar/unarchive modules

[http://github.com/pileofrogs/ansible\_unarchive](http://github.com/pileofrogs/ansible_unarchive)

It copies gzipped tar files to your host and unpacks them where you say. It does NOTHING else. More features will be added if people want them. The readme on the github above lists a lot of ideas. I’ll make a pull request when this is more usable.

I wasn’t sure of the best way to host this module in it’s present state. It’s not at all ready for a pull request, but I wanted to get started pushing stuff out to the world. Any advice on that would be great.

And of course, any advice on this unarchive module would be fantastic.

Thanks everyone  
-Dylan
