>
> *Not sure if you already had an answer for this. Just came across with 
> this requirement and found a solution. *
>

*you might want to install PowerShell on your Ansible master server #sudo 
> install powershell,  Depending on your Linux distro and version you may 
> have to set an updated *MS repo 
> <https://docs.microsoft.com/en-au/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6>
> .
>
> *#sudo pwsh*
> *PS /home/user/> Install-Module vmware.powercli*
> *PS /home/user/> Set-PowerCLIConfiguration -InvalidCertificateAction 
> Ignore -Scope AllUsers*
>
> *Create a PowerShell Script:*
>
> *Connect-VIServers Get-Host >> test.ps1*
>
> *Call the above ps script using ansible "command" option:*
>
> *---*
> *- hosts: localhost*
> *  tasks:*
> *    - name: Get esxi hosts*
> *      command: pwsh test.ps1*
>
>
> *Regards,*
> *Kadirvel A*
>

On Monday, 22 May 2017 17:18:42 UTC+5:30, Bob Nian wrote:
>
> Is it possible to use powercli in Ansible? This is because I am trying to 
> harden an EXSi host but I am trying simpler code first which is disabling 
> SSH service. I've created two files, one is for my powercli script and 
> another is a .yml file. However, I encountered an error.
>
> This is how it look: 
> *script.ps1*
>
> Get-VMHost | Foreach {
>   {Stop-VMHostService -HostService ($_ | Get-VMHostService | Where {$_.Key 
> -eq $
> }
>
> *playbook.yml*
> ---
> # This playbook tests the script module on ESXi hosts
>
> - name: Run powercli script
>   hosts: all
>   gather_facts: false
>   tasks:
>     - name: Run powercli script
>       script: script.ps1
>
> *Error*
>
>
>
> *fatal: [esxi-host]: FAILED! => {"changed": true, "failed": true, "rc": 2, 
> "stderr": "Shared connection to 192.168.1.190 closed.\r\n", "stdout": 
> "//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: line 
> 1: Get-VMHost: not 
> found\r\n//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: 
> line 1: Foreach: not 
> found\r\n//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: 
> line 2: syntax error: unexpected \"(\"\r\n", "stdout_lines": 
> ["//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: line 
> 1: Get-VMHost: not found", 
> "//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: line 
> 1: Foreach: not found", 
> "//.ansible/tmp/ansible-tmp-1495450802.21-237546974052981/script.ps1: line 
> 2: syntax error: unexpected \"(\""]} [WARNING]: Could not create retry file 
> '/etc/ansible/playbook.retry'.[Errno 13] Permission denied: 
> u'/etc/ansible/playbook.retry'*
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cb4de0e8-293d-4725-9428-be922c647a00%40googlegroups.com.

Reply via email to