Azure-cli: Unable to pipe output into az

Created on 21 Nov 2016  Â·  10Comments  Â·  Source: Azure/azure-cli

Is this expected or am i doing something wrong?
I'm simply trying to pipe in the resource group name:

~$ echo TMP | az appservice web list -g
usage: az appservice web list [-h] [--output {json,tsv,list,table,jsonc}]
                              [--verbose] [--debug] [--query JMESPATH]
                              --resource-group RESOURCE_GROUP_NAME
az appservice web list: error: argument --resource-group/-g: expected one argument

~$ echo TMP | az appservice web list -g -
Resource group '-' could not be found.

~$ echo TMP | az appservice web list -
usage: az appservice web list [-h] [--output {json,tsv,list,table,jsonc}]
                              [--verbose] [--debug] [--query JMESPATH]
                              --resource-group RESOURCE_GROUP_NAME
az appservice web list: error: argument --resource-group/-g is required

xargs is the only workaround i could come up with, but this is as flexible as a brick:

~$ echo TMP | xargs az appservice web list -g
[
  {
    "appServicePlanId": "/subscriptions/6dcbf69c-2e40-451d-b00a-fbc938812364/resourceGroups/TMP/providers/Microsoft.Web/serverfarms/ServicePlanba2b6dac-987b",
    "availabilityState": "DisasterRecoveryMode",
    "clientAffinityEnabled": true,
...
Infrastructure bug

Most helpful comment

For xargs, please make sure to use -n 1 to tell xargs only take one item each time.

az group list --query '[].name' --output list| xargs -n 1 az group show -n 

All 10 comments

Try echo TMP | xargs az appservice web list -g @-

The other option is shell-substitution like
a. az appservice web list -g $rgName
b. az appservice web list -g `any command which produces a single value`

With xargs, these are the 2 main standard patterns. Please quot other commands which handles better.

//cc: @johanste

~$ echo TMP | az network lb list -g @- -o table
ResourceGroup    Name    Etag                                      Location    ProvisioningState    ResourceGuid
---------------  ------  ----------------------------------------  ----------  -------------------  ------------------------------------
TMP              LBONE   W/"04e13a55-b4d4-412b-b084-0f26b8217037"  westeurope  Succeeded            becadea0-c9a6-43b0-bd07-585fb2a9eb56

This is good enough for now. Thanks.

I know this issue is closed, but I have a similar problem with the pipeline [could be well due my lack of knowledge on bash pipelines]. I want to get my resource group chef-lab.

Ex1: It does exist on my group list
bash [root@centos-linux-7 Azure]# az group list --query '[].name' --output list … chef-lab … …
Ex2: I can show, i.e. it does exist:
bash [root@centos-linux-7 Azure]# az group show --name chef-lab { "id": "…", .. }
Ex3: When I want to show the pipeline output per group, it fails:
bash [root@centos-linux-7 Azure]# az group list --query '[].name' --output list|az group show -n usage: az group show [-h] [--output {json,tsv,list,table,jsonc}] [--verbose] [--debug] [--query JMESPATH] --name RESOURCE_GROUP_NAME az group show: error: argument --name/-n: expected one argument
Ex4: Tried xargs, no luck:
bash [root@centos-linux-7 Azure]# az group list --query '[].name' --output list|xargs az group show -n @- Failed to open file -
Ex5: Tried to write a file and read, no luck too...
bash [root@centos-linux-7 Azure]# awk '{print $0}' azurelistgroups | xargs az group show --name @- Failed to open file -
Any input is appreciated....

For xargs, please make sure to use -n 1 to tell xargs only take one item each time.

az group list --query '[].name' --output list| xargs -n 1 az group show -n 

Just confirmed that this is no longer working.

echo tjp-rg | az group show -g @-

Parameter 'resource_group_name' must conform to the following pattern: '^[-\\w\\._\\(\\)]+$'.
Traceback (most recent call last):
  File "e:\github\knack\knack\cli.py", line 197, in invoke
    cmd_result = self.invocation.execute(args)
  File "e:\github\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 350, in execute
    cmd.exception_handler(ex)
  File "e:\github\azure-cli\src\azure-cli-core\azure\cli\core\util.py", line 40, in empty_on_404
    raise ex
  File "e:\github\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 325, in execute
    result = cmd(params)
  File "e:\github\azure-cli\src\azure-cli-core\azure\cli\core\commands\__init__.py", line 185, in __call__
    return self.handler(*args, **kwargs)
  File "e:\github\azure-cli\src\azure-cli-core\azure\cli\core\__init__.py", line 420, in default_command_handler
    result = op(**command_args)
  File "e:\github\azure-cli\env\lib\site-packages\azure\mgmt\resource\resources\v2017_05_10\operations\resource_groups_operations.py", line 274, in get
    'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
  File "E:\github\azure-cli\env\lib\site-packages\msrest\serialization.py", line 488, in url
    data = self.validate(data, name, required=True, **kwargs)
  File "E:\github\azure-cli\env\lib\site-packages\msrest\serialization.py", line 568, in validate
    raise ValidationError(key, name, value)
msrest.exceptions.ValidationError: Parameter 'resource_group_name' must conform to the following pattern: '^[-\\w\\._\\(\\)]+$'.

@tjprescott, don't you get the same error if you run az group show -g tjp-rg?

@johanste correct Sorry I read this wrong. No, I don't get this error if I type the name normally.

@tjprescott, then it is unrelated to reading from stdin. The resource group name is considered invalid by the SDK - presumably because that's what the swagger says. I'd suggest closing this issue unless there are other reasons why we believe that reading from STDIN doesn't work as expected...

@johanste see my PR.

Was this page helpful?
0 / 5 - 0 ratings