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/4be193d1-a5f5-48b8-b5d7-7bf5de98d016n%40googlegroups.com.

Reply via email to