Extract a directory from tar archive using ansible unarchive

Viewed 8627

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?

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"
Related