Skip to content

az role definition create --role-definition example fails #15370

Closed

Description

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug

When trying to create a new custom role definition using Cloud Shell Azure CLI, my script keeps failing.
I have tried to use the the example from the az role definition create --role-definition section in the Docs page, but also get an error here. All other examples I have located, utilize an external JSON file, and I like to use the script with embedded JSON code, for easier management and documentation.

Reference:
az role definition
https://docs.microsoft.com/en-us/cli/azure/role/definition?view=azure-cli-latest#az_role_definition_create

Example code (subscription id replaced with id from my tenant):

az role definition create --role-definition '{
    "Name": "Contoso On-call",
    "Description": "Perform VM actions and read storage and network information.",
    "Actions": [
        "Microsoft.Compute/*/read",
            "Microsoft.Compute/virtualMachines/start/action",
            "Microsoft.Compute/virtualMachines/restart/action",
            "Microsoft.Network/*/read",
        "Microsoft.Storage/*/read",
            "Microsoft.Authorization/*/read",
        "Microsoft.Resources/subscriptions/resourceGroups/read",
        "Microsoft.Resources/subscriptions/resourceGroups/resources/read",
        "Microsoft.Insights/alertRules/*",
            "Microsoft.Support/*"
    ],
    "DataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/*"
    ],
    "NotDataActions": [
        "Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"
    ],
    "AssignableScopes": ["/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]
}'

The script produces this error:

ArgumentParseError: unrecognized arguments: On-call,
    Description: Perform VM actions and read storage and network information.,
    Actions: [
        Microsoft.Compute/*/read,
            Microsoft.Compute/virtualMachines/start/action,
            Microsoft.Compute/virtualMachines/restart/action,
            Microsoft.Network/*/read,
        Microsoft.Storage/*/read,
            Microsoft.Authorization/*/read,
        Microsoft.Resources/subscriptions/resourceGroups/read,
        Microsoft.Resources/subscriptions/resourceGroups/resources/read,
        Microsoft.Insights/alertRules/*,
            Microsoft.Support/*
    ],
    DataActions: [
        Microsoft.Storage/storageAccounts/blobServices/containers/blobs
...


The example in the documentation is expected to be usable in any subscription, just with a custom subscription ID added.
Used environment is the Cloud Shell Azure CLI in PowerShell mode.

Activity

  1. ghost added
    needs-triageThis is a new issue that needs to be triaged to the appropriate team.
    on Sep 30, 2020
  2. ghost added
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Sep 30, 2020
  3. ghost removed
    needs-triageThis is a new issue that needs to be triaged to the appropriate team.
    on Sep 30, 2020
  4. removed
    questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
    on Sep 30, 2020
  5. added this to the S177 milestone on Sep 30, 2020
  6. yonzhan commented on Sep 30, 2020

    @yonzhan
    Collaborator

    add to S177

  7. removed this from the S179 milestone on Nov 28, 2020
  8. 16 remaining items

  9. added this to the S188 milestone on May 21, 2021
  10. teresaritorto commented on Oct 8, 2026

    @teresaritorto
    Contributor

    Closing as a shell-quoting behavior rather than a CLI defect.

    If az role definition create still fails on current CLI with input that PowerShell passes as a single argument, please open a fresh issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions