简体   繁体   中英

Cannot convert string to boolean - ansible to powershell on linux

I read this whole thread about how to pass boolean values to a parameter to powershell on Linux. Nothing worked for me.

My code in Ansible is as follows:

- name: Install PowerCLI
  shell: pwsh -Command "Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCEIP:$False -Confirm:$False -InvalidCertificateAction Ignore"

I've used many variants, such as -ParticipateInCEIP:False , or -ParticipateInCEIP False , or -ParticipateInCEIP $false , but I get always the same error, that it expects boolean, but I sent string.

I am running this Ansible task against a Linux machine with Powershell installed.

Any tips on how to make it work?

Best,

Francis

When you shell: pwsh -Command "something -switch:$powershellVariable" , with double quotes, $powershellVariable will be evaluated by the Linux shell before passing it to PowerShell.

Unless you have an actual $powershellVariable defined in your shell, it will be passed to PowerShell as something -switch:

Try rewriting with single quotes:

  shell: pwsh -Command 'Set-PowerCLIConfiguration -Scope AllUsers -ParticipateInCEIP:$False -Confirm:$False -InvalidCertificateAction Ignore'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM