Hello !
Thank you for posting on Microsoft Learn.
IMHO, your current approach might work within Azure Automation and you will find no dependency management required but it is kind of messy for DEV and version control and hard to debug or unit test modularly.
You can try to bundle your runbook and modules into a .zip
file and upload it via Azure Automation or through Azure CLI. Inside the runbook, you can then use:
import sys
sys.path.append('/path/to/your/modules')
But, Azure Automation doesn't allow you to define a custom path directly in cloud execution so this is only practical if uploaded to a custom worker (for example Hybrid Worker).
You can also, set up a Hybrid Worker on a VM where you control the environment. There, your Python environment can:
- Use relative imports
- Load from folders
- Pull from DevOps
- Work like normal Python
But if you're strictly using Azure cloud workers and want to keep modularity:
Convert your .py
files to base64 strings.
Decode and exec()
them dynamically in the main runbook.
import base64 code = base64.b64decode(b'...base64encodedcode...') exec(code)