0

I have these azure-cli2 (which is python based) commands for creating rbac user and few other activities

az ad user create --display-name "user" --password Pass@word1 --user-principal-name "[email protected]"  --mail-nickname user
az role assignment create --role Contributor --assignee "[email protected]"
az ad sp create-for-rbac -n "testapp"

I am using the subprocess.check_output() to run these commands from python.

Is there any way directly initiate azure-cli commands from python

I am expecting for something like this:

import azure-core-cli
azure-core-cli.mycommand(param)

PS: I know ,I can get same functionality using azure Python SDK

3
  • Wouldn't it be a better idea to use Azure SDK directly in your script? After all the CLI is written as an application instead of a library. Commented May 8, 2018 at 15:57
  • @Troy Dai I will but that will take some time and till then I have to use this version with the variation suggested by Alex Commented May 9, 2018 at 2:33
  • Possible duplicate of How to run Azure CLI commands using python? Commented Oct 18, 2018 at 11:16

1 Answer 1

2

Based on this file, try:

from azure.cli.core import get_default_cli

get_default_cli().invoke(['ad', 'user', 'create', '--display-name', 'user', ...])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.