Launch powershell script with argument by ansible

Hi everyone,

My ansible version is : 2.2.0.0

I make a powershell script to deploy a new VM on vcenter.

Ansible correctly work with windows system but i have some trouble.

I would like ansible take my arguments for the script for each new host by the definition hots file in host_vars

But I don’t know how to do that.

command line for ansible :
ansible -i /etc/ansible/windows_prod INTERNAL65 -m script -a /etc/ansible/roles/powershell/files/deploy.ps1

/etc/ansible/roles/powershell/files/deploy.ps1 :
C:\AutoDeploy\final_test.ps1 -VMName TEST-AUTO -Cluster Test -Template Windows2012-TMPL -User franck -Password garrot -HostName TEST-AUTO -IPeth0 xx.xx.xx.xx -SNMeth0 xx.xx.xx.xx -DNSPeth0 xx.xx.xx.xx -DNSSeth0 xx.xx.xx.xx

I try to change my argument by this method :

in /etc/ansible/roles/powershell/files/deploy.ps1 :
C:\AutoDeploy\final_test.ps1 -VMName {{ VMName }} -Cluster Test -Template Windows2012-TMPL -User franck -Password garrot -HostName {{ HostName }} -IPeth0 {{ IPeth0 }} -SNMeth0 {{ SNMeth0 }} -DNSPeth0 {{ DNSPeth0 }} -DNSSeth0 {{ DNSSeth0 }}

and in the definition host file i add arguments, for example :
VMName: TEST-AUTO
HostName: TEST-AUTO

Finally that isn’t working.

If someone can help me …

Best regards.

What error messages do you see?

Try running your playbook with -v or -vvvvvv to see variables being set and command being run.

I’m not sure if it can be used from command line but seeing as you are using 2.2 perhaps try https://docs.ansible.com/ansible/win_shell_module.html