1

I'm trying to create a directory in a Windows machine and after that copy a file inside the directory.

The modules used are win_file and win_copy. This is the code:

- name: "win_winrm | main.yml | Create temporary dir 'tmp_ansible' on C:Sistemas unit"
  win_file:
    path: C:\Sistemas\tmp_ansible
    state: directory

- name: "win_winrm | main.yml | Copy ConfigureRemotingForAnsible.ps1 script into Windows machine"
  win_copy:
    src: files/ConfigureRemotingForAnsible.ps1
    dest: C:\Sistemas\tmp_ansible\ConfigureRemotingForAnsible.ps1

The win_file modules fails with a strange error that doesn't show any stdout.

This is the output:

TASK [win_winrm : win_winrm | main.yml | Create temporary dir 'tmp_ansible' on C:Sistemas unit] ***
[WARNING]: Error deleting remote temporary files (rc: 1, stderr: #< CLIXML
<Objs Version="1.1.0.1"
xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress"
RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>Sy
stem.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing
modules for first use.</AV><AI>0</AI><Nil
/><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><S
S="Error">Remove-Item : Cannot find path
'C:\Users\TEMP\AppData\Local\Temp\ansible-
tmp-1674134258.9689112-102-136885899008081' _x000D__x000A_</S><S
S="Error">because it does not exist._x000D__x000A_</S><S S="Error">At line:2
char:1_x000D__x000A_</S><S S="Error">+ Remove-Item
'C:\Users\TEMP\AppData\Local\Temp\ansible-tmp-1674134258.
..._x000D__x000A_</S><S S="Error">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~…
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: }
fatal: [wsy01iedi.rmasede.grma.net]: FAILED! => {"msg": "Unexpected failure during module execution.", "stdout": ""}

Credentials used are tested manually and working and the user has admin permissions.

Just to discard it is not a problem related to the win_file module when trying to create the directory, I have tried to directly copy the file to an existing directory with the module win_copy. Same error.

In fact, the automation works in some servers, but in most of them, it doesn't.

As this is an automation for configuring WinRM in virtual machines hosted in VMWare vCenter, the ansible_connection method used is vmware_tools.

EDITED:

I found the issue. When ansible connects to a windows server using the vmware_tools method, the user profile is not created in the server, so ansible fails because it can not find the path of the user profile (C:\Users\USER).

If I try the same automation but using the WinRM connection method (obv in a server where WinRM is already configured), it works. When I log in to the server manually, I can see that the user profile path has been just created.

Casti
  • 11
  • 2
  • The username is `TEMP`? – stackprotector Jan 19 '23 at 21:26
  • No, the username is EY01632, an Active Directory user – Casti Jan 20 '23 at 09:07
  • Then there is maybe something wrong with your environment, at least uncommon. `C:\Users\TEMP\AppData\Local\Temp` is really your expected TMP path? – stackprotector Jan 20 '23 at 16:11
  • I have found that in the servers where the automation works the path C:\Users\EY01632 is created, but in the servers where it doesn't work, that path doesn't exist. – Casti Jan 23 '23 at 08:14
  • I found the issue, but I don't know how to resolve it. When ansible first logs in to a windows server that has been just created (deployed in vmware vcenter), it fails because the user profile is not created (the system creates a user profile the first time that a user logs on to a computer), so it doesn't find the path of the user profile (C:\Users\EY01632). – Casti Jan 23 '23 at 19:52
  • Are the servers, where it doesn't work, already domain joined? – stackprotector Jan 23 '23 at 20:03
  • Yes, they are joined correctly in their domains – Casti Jan 24 '23 at 10:49

1 Answers1

0

My problem is that vmware_tools.py's function _fetch_file_from_vm() uses vmware_host as url address. This is fqdn address, that my ansible machine cannot resolve.

Thomas
  • 1
  • 1