[Python] Getting Azure Credentials from Hybrid Worker in Azure Automation with Python

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have an automation account with a bunch of stored credentials. In the past I typically use Powershell and using Get-AutomationPSCredential has worked great in the past. However I need to get some credentials into a Python script that is running from a hybrid worker. All of my research says to use the automationassets module, but apparently this only works when running it from Azure (Get Azure Automation Runbook Credential in Python).

    Running this script from a hybrid worker

    #!/usr/bin/env python3
    import automationassets

    print("hello world")
    cred = automationassets.get_automation_credential("TestCredentials")
    print (cred["username"])
    print (cred["password"])
    print ("---DONE---")


    I get this error:

    Traceback (most recent call last):
    File "C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandboxes\prccrwfo.uqy\Temp\u4krn2px.peo\2067bebf-6afe-4427-a1ba-ebe41539ff53", line 5,
    in <module> cred = automationassets.get_automation_credential("TestCredentials")
    File "C:\Python39\automationassets.py", line 126,
    in get_automation_credential credential = _get_asset(_KEY_CREDENTIAL, name)
    File "C:\Python39\automationassets.py", line 72,
    in _get_asset return_value = _get_asset_value(local_assets_file, asset_type, asset_name)
    File "C:\Python39\automationassets.py", line 55,
    in _get_asset_value for asset, asset_values in local_assets.iteritems():
    AttributeError: 'dict' object has no attribute 'iteritems'


    And that same script with an additional import

    import automationassets
    from automationassets import AutomationAssetNotFound


    Throws this error:

    Traceback (most recent call last):
    File "C:\ProgramData\Microsoft\System Center\Orchestrator\7.2\SMA\Sandboxes\1v03pjym.qll\Temp\rv4yiqnf.c3v\4a5b24ae-bd26-40e6-82cc-86cf36915077", line 3,
    in <module> from automationassets import AutomationAssetNotFound
    ImportError: cannot import name 'AutomationAssetNotFound' from 'automationassets' (C:\Python39\automationassets.py)


    Is it possible to get Azure credentials into a Python script running from a hybrid worker in Azure automation?

    Continue reading...

Compartilhe esta Página