Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract a directory from tar archive using ansible unarchive

Tags:

tar

ansible

I'd like to extract one directory from tar file.

In Linux OS for install directory unpacking - I simply do:

tar -xvf ingres.tar install

For ansible I've tried:

unarchive:
  remote_src: yes
  src: /ingres/ingres.tar
  dest: /ingres
  extra_opts:
    - "install"

But it doesn't work of course. Any idea?

like image 605
robson Avatar asked Mar 05 '23 09:03

robson


1 Answers

The GNU tar command has an option to select archive members: --add-file. Section 6.2 of the manual mentions it:

If a file name begins with dash (-), precede it with --add-file option to prevent it from being treated as an option.

However, it works for other files too, which means you can specify this option in the extra_opts of your task to select file(s) or directories to extract:

unarchive:
  remote_src: yes
  src: /ingres/ingres.tar
  dest: /ingres
  extra_opts:
    - "--add-file"
    - "install"
like image 84
Ben Companjen Avatar answered Mar 08 '23 00:03

Ben Companjen