Skip to content
Advertisement

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

Advertisement

Answer

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'
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement