# win\_copy azure ansible module not working

**URL:** <https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082>\
**Category:** Ansible Project\
**Tags:** azure, windows\
**Created:** [April 9, 2019, 10:19am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082 "2019-04-09T10:19:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 9, 2019, 10:19am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/1 "2019-04-09T10:19:18Z")

</div>

[windows]

127.0.0.1

[windows:vars]

ansible\_user: admin

ansible\_password: admin

ansible\_connection: winrm

ansible\_winrm\_transport: basic

ansible\_port: 5986

ansible\_winrm\_server\_cert\_validation: ignore

validate\_certs: false

Results while running ansible playbook:

fatal: [localhost]: FAILED! =\> {

“changed”: false,

“dest”: “C:\”,

“module\_stderr”: “”,

“module\_stdout”: “”,

“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,

“operation”: “folder\_copy”,

“rc”: 0,\*\*\_

---

<div class="post-metadata">

**Author:** ![vinod93pop](https://avatars.discourse-cdn.com/v4/letter/v/ea5d25/32.png) [@vinod93pop](https://forum.ansible.com/u/vinod93pop)\
**Post date:** [April 10, 2019, 5:26am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/2 "2019-04-10T05:26:00Z")

</div>

Hi ,

Error says in dest. Can you try to put in any other destination with absolute path ?

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 10, 2019, 9:58am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/3 "2019-04-10T09:58:03Z")

</div>

Hi,  
We have tried changing the destination to C://Toolsinstall/.  
But the problem here is win\_copy , which is not allowing to copy the file to remote server.

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 10, 2019, 9:58am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/4 "2019-04-10T09:58:31Z")

</div>

Please suggest any other alternative…

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [April 11, 2019, 7:00am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/5 "2019-04-11T07:00:28Z")

</div>

If your inventory is targeting localhost then that means it’s trying to run a Windows module on the Ansible controller which won’t work. You cna use the azure\_rm\_virtualmachine module to spin up a host but then you will have to use something like ‘add\_host’ [1] to add the host for the current execution then change the play to that new host.

[1] [https://docs.ansible.com/ansible/latest/modules/add\_host\_module.html](https://docs.ansible.com/ansible/latest/modules/add_host_module.html)

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 12, 2019, 8:31am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/6 "2019-04-12T08:31:46Z")

</div>

Hi Jordan,

Can you please describe it briefly? You want us to create a new VM and then point that IP to add\_host?

---

<div class="post-metadata">

**Author:** ![CORLEONE](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@CORLEONE](https://forum.ansible.com/u/CORLEONE)\
**Post date:** [April 12, 2019, 8:57am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/7 "2019-04-12T08:57:06Z")

</div>

its a module failure…is the localhost linux or windows.???..win\_copy works for windows …for rest use copy module

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 12, 2019, 9:06am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/8 "2019-04-12T09:06:45Z")

</div>

localhost is windows. And we are using win\_copy for copying the file. Any alternative for this?

---

<div class="post-metadata">

**Author:** ![CORLEONE](https://avatars.discourse-cdn.com/v4/letter/c/9f8e36/32.png) [@CORLEONE](https://forum.ansible.com/u/CORLEONE)\
**Post date:** [April 12, 2019, 10:31am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/9 "2019-04-12T10:31:50Z")

</div>

If u want to copy from local to remote u should mention -host: remote\_host…i think u r using localhost

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 15, 2019, 4:53am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/10 "2019-04-15T04:53:44Z")

</div>

I changed localhost to remote\_host as suggested, but while running the playbook getting error as “no hosts matched”.

Is there any possible way that we can get on call to discuss further…Please suggest…!!!

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [April 15, 2019, 6:27pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/11 "2019-04-15T18:27:28Z")

</div>

Please clarify a couple questions:

1. You’re running the ansible command from a Linux (RedHat, Ubuntu, CentOS, Debian) system, correct?

2. The playbook you’re using has these tasks:

- name: Copy script from local to remote server

win\_copy:

src: files

dest: C:\

register: myfile

- debug: var=myfile

- win\_command: powershell.exe -ExecutionPolicy ByPass -File C:/userdata-winsetup.ps1

1. The directory where your playbook and inventory file reside also have a directory called “files”.

2. Your inventory file has this section:

[windows]

127.0.0.1

Based on your inventory file, you’re attempting to run the commands in the playbook on the system you’re running Ansible on. Your inventory file probably needs the _windows_ server listed in the “[windows]” section like this:

[windows]

[MyWinSys01.example.com](http://MyWinSys01.example.com)

Then when you run your playbook with Ansible, it will connect using the “winrm” protocol and login with “admin” (password: “admin”), then copy the files from ".\files" to "c:" on the remote system.

Once you’ve validated all that, please re-run the playbook with “-v” (or more for additional verbose output) and post it here.

Thanks,

DanL

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 16, 2019, 3:12pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/12 "2019-04-16T15:12:07Z")

</div>

Hi,

We are running the playbook via azure cloud shell “bash” editor.

The source file and the inventory are placed in the same folder and while running playbook we are invoking the playbook and below is the command:

ansible-playbook -i inventory wincopy.yml

We are getting the below error:  
“fatal: [remote host]: UNREACHABLE! =\> {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: connect to host remote\_host port 22: Connection timed out”, “unreachable”: true}”

We are trying to copy the file from Azure cloud shell to the remote machine, but the error says ssh connection time out(Ideally it should be **windows exception as we are using windows** but it’s trying ssh like linux machine)

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [April 17, 2019, 12:57pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/13 "2019-04-17T12:57:37Z")

</div>

I don’t do much Ansible work on Windows systems, but the message “Failed to connect to host via ssh” seems to imply that the connection type for that remote host isn’t setup for Windows. At minimum you’ll need to setup these connection variables (connection type, user, and password) as shown here:  
[https://docs.ansible.com/ansible/latest/user\_guide/windows\_winrm.html#inventory-options](https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html#inventory-options)

Once you get that setup, try re-running your playbook but add a “-vvv” (verbose output) to show more details on the error:  
ansible-playbook -i inventory -vvv wincopy.yml

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 18, 2019, 4:19am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/14 "2019-04-18T04:19:15Z")

</div>

Hi,

We are using the mentioned connection variables and below are the inventory file details:

[windows]  
remote\_host  
[windows:vars]  
ansible\_user: admin  
ansible\_password: admin  
ansible\_connection: winrm  
ansible\_winrm\_transport: basic  
ansible\_port: 5986  
ansible\_winrm\_server\_cert\_validation: ignore  
validate\_certs: false

And executed playbook as mentioned by placing -vvv:

[WARNING]: Unable to parse /home/f2/.ansible/inventory as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAYBOOK: wincopy.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in wincopy.yml

PLAY [Configurations for windows instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
META: ran handlers

TASK [A single debug statement] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/f2/.ansible/wincopy.yml:7  
\<remote\_host\> ESTABLISH SSH CONNECTION FOR USER: None  
\<remote\_host\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/f2/.ansible/cp/56de033974 [WARNING]: Unable to parse /home/f2/.ansible/inventory as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAYBOOK: wincopy.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
1 plays in wincopy.yml

PLAY [Configurations for windows instance] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
META: ran handlers

TASK [A single debug statement] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /home/f2/.ansible/wincopy.yml:7  
\<remote\_host\> ESTABLISH SSH CONNECTION FOR USER: None  
\<remote\_host\> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/f2c34c90-9efb-4ea2-afcc-f24ace01/.ansible/cp/56de033974 40.71.47.192 ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’"‘’  
\<remote\_host\> (255, ‘’, ‘ssh: connect to host remote\_host port 22: Connection timed out\r\n’)  
fatal: [remote\_host]: UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: connect to host remote\_host port 22: Connection timed out”,  
“unreachable”: true  
}  
to retry, use: --limit @/home/f2/.ansible/wincopy.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
remote\_host : ok=0 changed=0 unreachable=1 failed=0 ‘/bin/sh -c ‘"’“‘echo ~ && sleep 0’”’"‘’  
\<remote\_host\> (255, ‘’, ‘ssh: connect to host remote\_host port 22: Connection timed out\r\n’)  
fatal: [remote\_host]: UNREACHABLE! =\> {  
“changed”: false,  
“msg”: “Failed to connect to the host via ssh: ssh: connect to host remote\_host port 22: Connection timed out”,  
“unreachable”: true  
}  
to retry, use: --limit @/home/f2/.ansible/wincopy.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
remote\_host : ok=0 changed=0 unreachable=1 failed=0

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [April 18, 2019, 1:11pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/15 "2019-04-18T13:11:08Z")

</div>

Somethign is wrong with your inventory file (format, access, etc) - this is why it’s not connecting to the Windows system using your connection information. Fix this and reply with the results.

---

<div class="post-metadata">

**Author:** ![gottumukkala\_srija](https://avatars.discourse-cdn.com/v4/letter/g/59ef9b/32.png) [@gottumukkala\_srija](https://forum.ansible.com/u/gottumukkala_srija)\
**Post date:** [April 22, 2019, 10:28am UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/16 "2019-04-22T10:28:41Z")

</div>

Hi,

I tried changing the format of the inventory but still the same issue. Not sure what else to be done. I mentioned all the necessary modules for windows connection.

Do you anything to suggest here?

Thanks in Advance.

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [April 22, 2019, 12:57pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/17 "2019-04-22T12:57:28Z")

</div>

You could upload all these files (playbook, inventory, sample file to copy, etc) to a temporary [GitHub.com](http://GitHub.com) or [GitLab.com](http://GitLab.com) repository for us to look at it. The “unable to parse inventory” probably means formatting or other weirdness, not a bug or problem with Ansible.

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [April 22, 2019, 9:24pm UTC](https://forum.ansible.com/t/win-copy-azure-ansible-module-not-working/30082/18 "2019-04-22T21:24:40Z")

</div>

The first thing you want to do is create an inventory with a Windows group that contains the generic WinRM connection vars like;

`  
[windows]

[windows:vars]  
ansible\_connection=winrm  
ansible\_port=5986  
ansible\_winrm\_transport=ntlm  
ansible\_winrm\_server\_cert\_validation=ignore

`

This group is empty as we use add\_host to add the new Azure VM to the host mid play. This host will be an in memory host and is not persisted once the play is complete. If you want to persist this then you should look at using a dynamic inventory but that is outside of the scope here. The reason we do this is to define generic connection vars like ‘ansible\_connection=winrm’, ‘ansible\_winrm\_server\_cert\_validation=ignore’ so we don’t have to do it in the play. You could define more vars here or in a group\_vars file but that’s dependent on what your play does.

From there you want a play similar to

`

- name: provision Windows host in Azure  
hosts: localhost  
gather\_facts: no  
vars:  
azure\_resource\_group: RG01  
azure\_vm\_name: WindowsVM01  
windows\_username: azure  
windows\_password: ‘s=3@W%qTDYtm%nWW’

tasks:

# This is not a full task, you still need to do the work around creating the resource group and other components.

# This is just a brief example to show you how to provision the Windows host, enable WinRM, and then connect to it

# with Ansible.

- name: provision Windows VM  
azure\_rm\_virtualmachine:  
admin\_username: ‘{{ windows\_username }}’  
admin\_password: ‘{{ windows\_password }}’  
os\_type: Windows  
image:  
offer: WindowsServer  
publisher: MicrosoftWindowsServer  
sku: 2016-Datacenter  
version: latest  
name: ‘{{ azure\_vm\_name }}’  
resource\_group: ‘{{ azure\_resource\_group }}’  
state: present  
register: azure\_vm

- name: set fact for VM extension PS script to run  
set\_fact:

# You should be sourcing your own script and not this one on GitHub. This is just an example of how to download

# a PS script from a URL and then invoke it using the VM extension.

azure\_vm\_extension\_ps: Invoke-Expression -Command ((New-Object System.Net.WebClient).DownloadString(‘[https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1](https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1)’))

- name: set fact for VM extension setings  
azure\_vm\_extension:  
commandToExecute: powershell.exe -ExecutionPolicy ByPass -EncodedCommand {{ azure\_vm\_extension\_ps | string | b64encode(encoding=‘utf-16-le’) }}

- name: set fact for newly create VM public IP address  
set\_fact:  
azure\_vm\_ip: ‘{{ azure\_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}’

- name: create Azure VM extension to enable HTTPS WinRM listener  
azure\_rm\_virtualmachine\_extension:  
name: winrm-extension  
resource\_group: ‘{{ azure\_resource\_group }}’  
virtual\_machine\_name: ‘{{ azure\_vm\_name }}’  
publisher: Microsoft.Compute  
virtual\_machine\_extension\_type: CustomScriptExtension  
type\_handler\_version: 1.9  
settings: ‘{{ azure\_vm\_extension | to\_json }}’  
auto\_upgrade\_minor\_version: yes

- name: wait for the WinRM port to come online  
wait\_for:  
port: 5986  
host: ‘{{ azure\_vm\_ip }}’  
timeout: 600

- name: add new Azure VM as a Windows host  
add\_host:  
name: ‘{{ azure\_vm\_ip }}’  
groups: windows  
ansible\_user: ‘{{ windows\_username }}’  
ansible\_password: ‘{{ windows\_password }}’

# Now that we have provisioned our new Windows host and added it to the in memory host inventory, we change our play

# to run on the windows group and then run our script

- name: deploy configuration to Windows host in Azure  
hosts: windows  
gather\_facts: no  
tasks:

- name: wait for the WinRM connection to be fully reachable  
wait\_for\_connection:

- name: gather facts about host  
setup:

# Your example had you copying the script with win\_copy then invoking it. Unless there were other files there, it is

# simpler to just use script instead.

- name: invoke setup script  
script: userdata-winsetup.ps1  
`

This playbook contains 2 plays;

1. The first play runs on localhost (Ansible controller) to provision the Azure VM so that Ansible can talk to it
2. The second play is targeted towards the ‘windows’ group which should contain our new Azure VM as the 1st play uses add\_host

I’ve left some comments in line to explain some of the steps a bit more but hopefully it is mostly self explanatory. I haven’t actually tested this so there could be some mistakes but the general workflow should work and give you enough info to continue onwards.

Thanks

Jordan
