Hello
Is it possible to run powercli commands instead of using scyrpt in *.ps1?
sth like this but example gives me error :(
tasks:
- name: Run PowerShell Command
shell: |
Connect-VIServer -Server <IP>-User administrator -Password
<Password>
Get-VMHost <nameofhost> | get-datastore local |Set-Datastore
-Name localdatastore
I have also tried with command: | also not working
środa, 11 września 2019 o 06:29:40 UTC+2 Angel Rengifo Cancino napisał(a):
> Actually, I usually run PowerCLI scripts from the Ansible controller
> without any issues. I just invoke shell module pointing to my PS1 script.
>
> On Mon, Sep 9, 2019 at 1:59 AM Abhijeet Kasurde <[email protected]>
> wrote:
>
>> Hi All,
>>
>> I am maintainer of VMware Ansible modules. I would strongly recommend to
>> use existing VMware Ansible modules since they are tested and works well
>> with existing setups. For current use case like disabling firewall, you can
>> use `vmware_host_service_manager` module. You can check this stackoverflow
>> answer - https://stackoverflow.com/a/48293497/1075324 for more details.
>>
>> Yes, It is possible to run powercli scripts against given ESXi. You need
>> to use a Windows machine as a delegate host since powercli will reside and
>> run on that same host. So long story short
>>
>> Ansible controller will communicate to Windows machine as a delegate host
>> and then that windows machine will communicate to ESXi host.
>>
>> You need to edit the existing powershell script to work with Ansible.
>> Since requires certain format for Ansible Powershell module. You can check
>> these sample powershell scripts with python helper modules -
>> https://github.com/Akasurde/ansible-vmware_update_manager and
>> https://github.com/mycloudrevolution/Ansible-Veeam
>>
>> Let me know if you any question around this.
>>
>> Thanks
>>
>> Abhijeet Kasurde
>> On Monday, September 9, 2019 at 4:56:57 AM UTC+5:30, kadir vel wrote:
>>>
>>> *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 [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/9f8f664a-f85d-4877-9d91-24c3884a8b14%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/9f8f664a-f85d-4877-9d91-24c3884a8b14%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/53fb8fa7-81c3-4b63-b907-ff408224e601n%40googlegroups.com.