I'm trying to get an Automation Account credential in my Python 3.8 runbook using a managed identity.
The current code looks like this.
from azure.identity import ManagedIdentityCredential
from azure.mgmt.automation import AutomationClient
from azure.mgmt.automation.operations import CredentialOperations
def get_credential(credential):
subscription_id = "xxxxxxxxxxxx"
automation_account = "xxxxxxxxxxxx"
# Create Managed Identity object
auth_client = ManagedIdentityCredential()
# Create Automation Client
client = AutomationClient(auth_client, subscription_id)
# Create Credential Operations Client
credential_client = CredentialOperations(client._client, client._config, client._serialize, client._deserialize)
# Get Credential
cred = credential_client.get(subscription_id, automation_account, credential)
return cred
The code gets the credential, but the problem I noticed is that this code only gets the credential object, which doesn't include the actual password that I'm looking for.
I've tried to find another way of getting the actual password, but haven't yet managed to find one.
Anyone know?
I have used the below code in Azure Automation Runbook to get the credentials.
import automationassets
from automationassets import AutomationAssetNotFound
# get a credential
cred = automationassets.get_automation_credential("{credential_name}")
print (cred["username"])
print (cred["password"])
Output-
You can also use this code in vs code by adding Azure Automation extension in it.
References-