2

I'm trying to set a windows Host through a VM using mac M1 but I'm having the following issue :

UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p "echo \~/.ansible/tmp"&& mkdir "echo \~/.ansible/tmp/ansible-tmp-1673021425.449706-14817-109103252041296" && echo ansible-tmp-1673021425.449706-14817-109103252041296="echo \~/.ansible/tmp/ansible-tmp-1673021425.449706-14817-109103252041296" ), exited with result 1", "unreachable": true}

I tried to set remote tmp through inventory, environment variable but still the same issue. I also tried setting it up through SSH and WinRM but still the same issue.

I had some other hosts (including windows too) that worked well, but this time I can't figure why it's not working. And I'd rather find the solution than creating a new VM.

3 Answers 3

1

Add the below lines in the host file(not config file).

[windows:vars]
remote_tmp = C:\Users\ans_user\Tmp
become_method = runas
ansible_shell_type = powershell
shell_type = powershell
1
  • Where is that "host file" to be found?
    – Dominique
    Commented Jan 23, 2023 at 14:14
1

The very first thing Ansible does after connecting to a remote host and before running your desired commands is to create some temporal folders.

As you can see in the error message, Ansible tried creating those temp folders but using Linux commands (umask, mkdir and the likes). That's the problem right there! Those commands don't exist on a Windows host.

Why Ansible thinks the host is "Unreachable" when it was able to connect, authenticate, and then run commands (although not the correct ones for the target platform)? No idea but it is defintely misleading (ie: the issue is not network related at all)

Anyway, you have to explicitly tell Ansible your remote host is Windows so it won't incorrectly assume a Linux shell. The Ansible variable that controls which shell to use is ansible_shell_type, which you can use in both, ad-hoc commands and in inventory files.

The two possible values for ansible_shell_type in the Windows world, are cmd or powershell. Which one to use will depend on how you have setup your Windows host. If you installed the Windows built-in SSH server it defaults to cmd unless you created a specific registry key to enable powershell.

Ansible documentation covers this topic.

Here's an ad-hoc example for a Windows host running default SSHd (ie: cmd) with password authentication (comma after the hostname is important!):

ansible all -i winhost, -u winuser -k -e ansible_shell_type=cmd -m win_ping

Equivalent inventory example:

[windows]
winhost

[windows:vars]
ansible_connection=ssh
ansible_user=winuser
ansible_password=winuserpassword
ansible_shell_type=cmd
0

I have the same problem of connectivity to a remote host with Windows Pro from a Debian central server, I have made all kinds of modifications, for example through the ad-hoc ansible command WindowsClient -m ping or through an automated playbook I have trying to ping but it has thrown a series of errors, in the inventory.yml file I have already made the corresponding modifications, and now it throws me the error that appears in the attached file that I am sending, I also send my inventory as an attachment, I would appreciate your guidance .

enter image description here

enter image description here

2
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Jun 27, 2023 at 16:43
  • I want to ping a remote host that has Windows 10 installed, from a central server with Debian operating system, I have tried to ping with ad hoc commands and through playbooks, in the Inventory.yml file I have already made the corresponding modifications, and now I get It throws the error that appears in the attached file that I am sending, I also send my inventory as an attached file, I would appreciate your guidance. Commented Jun 28, 2023 at 18:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .