1

My playbook with shell module

 - name: Unarchive  macports from local machine
      shell: |
        tar -xvf MacPorts-2.6.2.tar.gz
        cd MacPorts-2.6.2
        ./configure 
        make
        make install

Error [WARNING]: Consider using the unarchive module rather than running 'tar'. If you need to use command because unarchive is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message. fatal: [X.X.X.X]: FAILED! => {"changed": true, "cmd": "tar -xvf MacPorts-2.6.2.tar.gz\ncd MacPorts-2.6.2\n./configure\nmake \nmake install\n", "delta": "0:00:00.026259", "end": "2020-06-03 15:54:26.259407", "msg": "non-zero return code", "rc": 2, "start": "2020-06-03 15:54:26.233148", "stderr": "tar: Error opening archive: Failed to open 'MacPorts-2.6.2.tar.gz'\n/bin/sh: line 1: cd: MacPorts-2.6.2: No such file or directory\n/bin/sh: line 2: ./configure: No such file or directory\nmake: * No targets specified and no makefile found. Stop.\nmake: * No rule to make target install'. Stop.", "stderr_lines": ["tar: Error opening archive: Failed to open 'MacPorts-2.6.2.tar.gz'", "/bin/sh: line 1: cd: MacPorts-2.6.2: No such file or directory", "/bin/sh: line 2: ./configure: No such file or directory", "make: *** No targets specified and no makefile found. Stop.", "make: *** No rule to make targetinstall'. Stop."], "stdout": "", "stdout_lines": []}

But i have tar.gz file in target machine, when I use unarchive module to untar facing below issue

TASK [Unarchive macports from local machine] ************************************************************************************************************************** fatal: [X.X.X.]: FAILED! => {"changed": false, "msg": "Failed to find handler for \"/Users/pru5/Documents/ansible/MacPorts-2.6.2.tar.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."} can someone help me to untar file in mac??

ZAriel
  • 35
  • 2
  • 10

2 Answers2

1

I installed jnu-tar, but I am not sure if that helped. Unarchive dint work and with no choice went for shell

name: extract tar
shell: |
  cd <file_path>
  tar -xvf <file_path/file_name>
ZAriel
  • 35
  • 2
  • 10
0

First point is to use Full paths with Ansible playbooks . I would recommend to make as two parts , first will be un-taring the file using Ansible native module unarchive , second part will configure and install using command or shell module

- name: Extract TAR
  unarchive:
    src: /Users/pru5/Documents/ansible/MacPorts-2.6.2.tar.gz
    dest: /tmp/MacPorts
- name: Install software
  command: cd /tmp/MacPorts && ./configure && make && make install
Shan Sunny
  • 92
  • 10
  • I tried that way but facing the below error. ``` TASK [Extract TAR] ********************************************************************************************************** fatal: [X.X.X.X]: FAILED! => {"changed": false, "msg": "Failed to find handler for \"/Users/pru5/Documents/ansible/MacPorts-2.6.2.tar.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."} – ZAriel Jun 03 '20 at 11:10
  • It seams you need gnu tar , Since Apple native tar package is BSD tar , So install gnu tar and retry. `brew install gnu-tar` – Shan Sunny Jun 03 '20 at 12:07
  • I installed gnu-tar in mac and when I run playbook, facing below error now ""An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'list' object has no attribute 'startswith' fatal: [X.X.X.X]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""} "" @Shan Sunny – ZAriel Jun 04 '20 at 07:24