- 1 year ago
ansible untar a file on a windows target
To untar a file on a Windows target using Ansible, you can use the unarchive
module with the appropriate parameters. However, since Windows doesn't have a built-in tar
command, you will need to have an external utility like 7-Zip installed on the Windows target machine to handle the extraction. Here's an example playbook:
yaml- name: Untar file on Windows target
hosts: windows_target
tasks:
- name: Copy tar file to Windows target
win_copy:
src: /path/to/archive.tar
dest: C:\temp\archive.tar
- name: Extract tar file using 7-Zip
win_command: C:\Program Files\7-Zip\7z.exe x C:\temp\archive.tar -oC:\temp
- name: Remove tar file
win_file:
path: C:\temp\archive.tar
state: absent
In this example, the playbook performs the following steps:
- Copies the tar file (
archive.tar
) from the Ansible control machine to the Windows target using thewin_copy
module. - Uses the
win_command
module to execute the 7-Zip utility (7z.exe
) on the Windows target to extract the contents of the tar file to a specified directory (C:\temp
in this case). - Removes the tar file from the Windows target using the
win_file
module.
Make sure to adjust the paths and filenames in the playbook to match your specific use case. Also, ensure that the 7-Zip utility is installed in the correct location on the Windows target machine and update the win_command
task accordingly if the installation path differs.
You can run this playbook using the ansible-playbook
command with the appropriate inventory and credentials for the Windows target machine.