Azure subscription validation with Ansible

%3CLINGO-SUB%20id%3D%22lingo-sub-2068578%22%20slang%3D%22en-US%22%3EAzure%20subscription%20validation%20with%20Ansible%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2068578%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20verify%20if%20an%20azure%20subscription%20exists%20using%20ansible.%26nbsp%3B%20I%20tried%20using%20az%20account%20show%20-s%20%7B%7Bsub%7D%7D%20but%20it%20fails%20with%20an%20error%20rather%20than%20returning%20that%20the%20%22subscription%20doesn't%20exist%20message%22.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20to%20handle%20this%20gracefully%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%2C%3CBR%20%2F%3ERK%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2075793%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20subscription%20validation%20with%20Ansible%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2075793%22%20slang%3D%22en-US%22%3EIt%20is%20solved%20with%20jq.%20Thanks!%3CBR%20%2F%3E%3CBR%20%2F%3Eaz%20account%20list%20%7C%20jq%20'.%5B%5D%20%7C%20select(.name%20%3D%3D%20%22%7B%7Bsub_name%7D%7D%22)%7C.name'%3C%2FLINGO-BODY%3E
New Contributor

I would like to verify if an azure subscription exists using ansible.  I tried using az account show -s {{sub}} but it fails with an error rather than returning that the "subscription doesn't exist message". 

 

How to handle this gracefully?

 

Thanks,
RK

1 Reply
It is solved with jq. Thanks!

az account list | jq '.[] | select(.name == "{{sub_name}}")|.name'