TechChain
TechChain

Reputation: 8942

unable to extract tar file though ansible unarchive module in macOS?

I have written a playbook which download the tar file & extract it to some directory in Mac.But when I run the playbook it fails with below error

"msg": "Failed to find handler for \"/Users/harmeet/.ansible/tmp/ansible-tmp-1549339698.75-251687957122076/config.tar9IXAUQ.gz\". Make sure the required command to extract the file is installed. Command \"/usr/bin/tar\" detected as tar type bsd. GNU tar required. Command \"/usr/bin/unzip\" could not handle archive.

Code for playbook

-name: Download the tar for sample config 
unarchive:
 src: http://someremoteurl/config.tar.gz 
dest: /Users/{{ansible_user}}/.myfolder/ 
remote_src: yes 
creates: /Users/{{ansible_user}}/.myfolder/config

If use a zip fie on remote Server such as http://someremoteurl/config.zip then this task works but for tar files it fails .

I have also installed gnu tar such as gtar & updated path in .bash_src after reviewing this question

Upvotes: 7

Views: 15705

Answers (2)

Thom Wiggers
Thom Wiggers

Reputation: 7054

If your default shell is zsh, then you should put the following in ~/.zshenv:

export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"

You can check if it's working correctly by:

ansible the-hostname -m command -a "which tar"

Upvotes: 1

TechChain
TechChain

Reputation: 8942

Actually on macOS it looks for GNU based tar archive module which was not found on mac. So if you use zip module for mac in ansible it will work but for that we may need to change the playbook file & it can create issues as i am using single playbook for both mac and linux. I used GNU based tar archive module to solve this issue.

I solved this issue by below steps

  1. Install gtar by homebrew. brew install gnu-tar
  2. Set path of gtar in .bashsrc file otherwise it will not able to use gtar for unarchive. Usually .bashsrc exist at $HOME path. if not exist then create it.

export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH" export MANPATH="/usr/local/opt/gnu-tar/libexec/gnuman:$MANPATH"

Thanks

Upvotes: 11

Related Questions