Also, I noticed this discussion: Ansible powershell module to be run on 
remote powershell on Linux machine. 
(https://groups.google.com/g/ansible-project/c/YZzYNEevzro)

Where Matt suggests:
That it [the module] is meant to be used with a Windows machine / over 
WinRM:


*Matt Davis*
*unread,*
*Oct 21, 2016, 1:24:06 PM*
**
**
**
*to Ansible Project*
*Some aspects of Ansible's Powershell support are currently built under the 
assumption that it would only ever run on Windows / over WinRM. There are a 
few things that would need to be moved around in order to allow "real" 
Ansible Powershell modules to work on Linux. By "real", I mean so that the 
module generation stuff works correctly whether the WinRM connection plugin 
runs it or something else, and that you can use our Powershell module API.*

So maybe that's my issue... ie not meant to run against Azure...


On Tuesday, March 14, 2023 at 3:28:04 PM UTC-4 Shawn Singh wrote:

> I'm trying to use Powershell from Ansible.
>
> This is the code:
>
> - name: Log into Azure
>
>   ansible.windows.win_powershell:
>
>     script: |
>
>       [CmdletBinding()]
>
>       param (
>
>         [String]
>
>         $TenantID,
>
>
>         [String]
>
>         $AccountID,
>
>
>         [SecureString]
>
>         $Secret
>
>       )
>
>       Connect-AzAccount -ServicePrincipal -TenantId $TenantID -Credential 
> $(New-Object -TypeName System.Management.Automation.PSCredential 
> -ArgumentList $AccountID, $Secret)
>
>     parameters:
>
>       TenantID: "{{ tenant }}"
>
>       AccountID: "{{ sp }}"
>
>       Secret: "{{ secret }}"
>
> The Connect-AzAccount command works, when executed from my machine 
> (running OS X) under pwsh; however, it blows up pretty ugly when executed 
> using ansible-playbook...
>
>
> fatal: [localhost]: FAILED! => {
>
>     "changed": false,
>
>     "module_stderr": "\u001b[31;1mParserError: 
> \u001b[0m/Users/j8683/.ansible/tmp/ansible-tmp-1678819559.972683-82400-269117048488035/AnsiballZ_win_powershell.ps1:159\u001b[0m\n\u001b[31;1m\u001b[0m\u001b[36;1mLine
>  
> |\u001b[0m\n\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m 159 | \u001b[0m 
> \u001b[36;1m\u0000\u001b[0m\u0000\u0000\u0000{\"module_entry\": 
> \"IyFwb3dlcnNoZWxsCgojIENvcHlyaWdodDogKGMpIDIwMjE 
> …\u001b[0m\n\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m
>  
>     | \u001b[31;1m 
> ~\u001b[0m\n\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m
>  
>     | \u001b[31;1munexpected token '\u0000', expected 'begin', 'process', 
> 'end', 'clean', 
> or\u001b[0m\n\u001b[31;1m\u001b[0m\u001b[36;1m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[0m\u001b[36;1m\u001b[31;1m\u001b[31;1m\u001b[36;1m\u001b[31;1m\u001b[36;1m
>  
>     | \u001b[31;1m'dynamicparam'.\u001b[0m\n",
>
>     "module_stdout": "",
>
>     "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
>
>     "rc": 1
>
> }
>
> Any ideas on what the win_powershell module might not like?
>
> This is the ansible version I'm using:
>
> ansible [core 2.14.0]
>
>   python version = 3.9.6 (default, Sep 26 2022, 11:37:49) [Clang 14.0.0 
> (clang-1400.0.29.202)] (/Library/Developer/CommandLineTools/usr/bin/python3)
>
>   jinja version = 3.1.2
>
>
> Thanks,
>
> Shawn
>

-- 
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/f3a8ab7d-ca56-44dd-a783-f54d5b816246n%40googlegroups.com.

Reply via email to