Skip to content

Commit ffad28f

Browse files
authored
Merge pull request #248834 from SnehaSudhirG/21Aug-Python2Update
added new code
2 parents 79fb2ce + 40bfd25 commit ffad28f

File tree

1 file changed

+21
-30
lines changed

1 file changed

+21
-30
lines changed

articles/automation/python-packages.md

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Manage Python 2 packages in Azure Automation
33
description: This article tells how to manage Python 2 packages in Azure Automation.
44
services: automation
55
ms.subservice: process-automation
6-
ms.date: 10/29/2021
6+
ms.date: 08/21/2023
77
ms.topic: conceptual
88
ms.custom: devx-track-python
99
---
@@ -16,7 +16,7 @@ For information on managing Python 3 packages, see [Manage Python 3 packages](./
1616

1717
## Import packages
1818

19-
1. In your Automation account, select **Python packages** under **Shared Resources**. Click **+ Add a Python package**.
19+
1. In your Automation account, select **Python packages** under **Shared Resources**. Select **+ Add a Python package**.
2020

2121
:::image type="content" source="media/python-packages/add-python-package.png" alt-text="Screenshot of the Python packages page shows Python packages in the left menu and Add a Python package highlighted.":::
2222

@@ -26,13 +26,13 @@ For information on managing Python 3 packages, see [Manage Python 3 packages](./
2626

2727
:::image type="content" source="media/python-packages/upload-package.png" alt-text="Screenshot shows the Add Python Package page with an uploaded tar.gz file selected.":::
2828

29-
After a package has been imported, it's listed on the **Python packages** page in your Automation account. To remove a package, select the package and click **Delete**.
29+
After a package has been imported, it's listed on the **Python packages** page in your Automation account. To remove a package, select the package and select **Delete**.
3030

3131
:::image type="content" source="media/python-packages/package-list.png" alt-text="Screenshot shows the Python 2.7.x packages page after a package has been imported.":::
3232

3333
## Import packages with dependencies
3434

35-
Azure automation doesn't resolve dependencies for Python packages during the import process. There are two ways to import a package with all its dependencies. Only one of the following steps needs to be used to import the packages into your Automation account.
35+
Azure Automation doesn't resolve dependencies for Python packages during the import process. There are two ways to import a package with all its dependencies. Only one of the following steps needs to be used to import the packages into your Automation account.
3636

3737
### Manually download
3838

@@ -46,7 +46,7 @@ Once the packages are downloaded, you can import them into your automation accou
4646

4747
### Runbook
4848

49-
To obtain a runbook, [import Python 2 packages from pypi into Azure Automation account](https://github.com/azureautomation/import-python-2-packages-from-pypi-into-azure-automation-account) from the Azure Automation GitHub organization into your Automation account. Make sure the Run Settings are set to **Azure** and start the runbook with the parameters. The runbook requires a Run As account for the Automation account to work. For each parameter make sure you start it with the switch as seen in the following list and image:
49+
To obtain a runbook, [import Python 2 packages from pypi into Azure Automation account](https://github.com/azureautomation/import-python-2-packages-from-pypi-into-azure-automation-account) from the Azure Automation GitHub organization into your Automation account. Make sure the Run Settings are set to **Azure** and start the runbook with the parameters. Ensure that Managed identity is enabled for your Automation account and has Automation Contributor access for successful import of package. For each parameter make sure you start it with the switch as seen in the following list and image:
5050

5151
* -s \<subscriptionId\>
5252
* -g \<resourceGroup\>
@@ -55,41 +55,32 @@ Once the packages are downloaded, you can import them into your automation accou
5555

5656
:::image type="content" source="media/python-packages/import-python-runbook.png" alt-text="Screenshot shows the Overview page for import_py2package_from_pypi with the Start Runbook pane on the right side.":::
5757

58-
The runbook allows you to specify what package to download. For example, use of the `Azure` parameter downloads all Azure modules and all dependencies (about 105).
59-
60-
After the runbook is complete, you can check the **Python packages** under **Shared Resources** in your Automation account to verify that the package has been imported correctly.
58+
The runbook allows you to specify what package to download. For example, use of the `Azure` parameter downloads all Azure modules and all dependencies (about 105). After the runbook is complete, you can check the **Python packages** under **Shared Resources** in your Automation account to verify that the package has been imported correctly.
6159

6260
## Use a package in a runbook
6361

64-
With a package imported, you can use it in a runbook. The following example uses the [Azure Automation utility package](https://github.com/azureautomation/azure_automation_utility). This package makes it easier to use Python with Azure Automation. To use the package, follow the instructions in the GitHub repository and add it to the runbook. For example, you can use `from azure_automation_utility import get_automation_runas_credential` to import the function for retrieving the Run As account.
62+
With a package imported, you can use it in a runbook. Add the following code to list all the resource groups in an Azure subscription:
6563

6664
```python
67-
import azure.mgmt.resource
68-
import automationassets
69-
from azure_automation_utility import get_automation_runas_credential
70-
71-
# Authenticate to Azure using the Azure Automation RunAs service principal
72-
runas_connection = automationassets.get_automation_connection("AzureRunAsConnection")
73-
azure_credential = get_automation_runas_credential()
74-
75-
# Intialize the resource management client with the RunAs credential and subscription
76-
resource_client = azure.mgmt.resource.ResourceManagementClient(
77-
azure_credential,
78-
str(runas_connection["SubscriptionId"]))
79-
80-
# Get list of resource groups and print them out
81-
groups = resource_client.resource_groups.list()
82-
for group in groups:
83-
print group.name
65+
#!/usr/bin/env python
66+
import os
67+
import requests
68+
# printing environment variables
69+
endPoint = os.getenv('IDENTITY_ENDPOINT') + "?resource=https://management.azure.com/"
70+
identityHeader = os.getenv('IDENTITY_HEADER')
71+
payload = {}
72+
headers = {
73+
'X-IDENTITY-HEADER': identityHeader,
74+
'Metadata': 'True'
75+
}
76+
response = requests.request("GET", endPoint, headers=headers, data=payload)
77+
print response.text
8478
```
8579

86-
> [!NOTE]
87-
> The Python `automationassets` package is not available on pypi.org, so it's not available for import onto a Windows machine.
88-
8980
## Develop and test runbooks offline
9081

9182
To develop and test your Python 2 runbooks offline, you can use the [Azure Automation Python emulated assets](https://github.com/azureautomation/python_emulated_assets) module on GitHub. This module allows you to reference your shared resources such as credentials, variables, connections, and certificates.
9283

9384
## Next steps
9485

95-
To prepare a Python runbook, see [Create a Python runbook](./learn/automation-tutorial-runbook-textual-python-3.md).
86+
To prepare a Python runbook, see [Create a Python runbook](./learn/automation-tutorial-runbook-textual-python-3.md).

0 commit comments

Comments
 (0)