# azure\_rm\_resourcegroup\_info usage help

**URL:** <https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771>\
**Category:** Ansible Project\
**Tags:** azure\
**Created:** [March 15, 2023, 2:53pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771 "2023-03-15T14:53:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![callmeshawn](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@callmeshawn](https://forum.ansible.com/u/callmeshawn)\
**Post date:** [March 15, 2023, 2:53pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/1 "2023-03-15T14:53:31Z")

</div>

Hello,

I have a playbook where I am calling my az commands via the command module.  
It works as expected.  
I’m trying to convert it to PoSH (different thread) and as I’m seeing some issues there, falling back to using specific Azure Modules.

When I execute the following playbook, it fails.

My intent is just to check for the existence of a resource group, authenticating using service principal.

I’ve got more int he original playbook; however, trying to start small, so I’ve only coded a couple tasks.

# get the subscription\_id, client\_id, tenant, secret

- name: read secret

include\_vars:

file: ../files/spsecret

no\_log: true

# check if resource group exists, pass in the args retrieved in previous step for authentication

- name: check if the rg already exists

azure.azcollection.azure\_rm\_resourcegroup\_info:

name: “np-{{ custom\_name }}-rg-east”

subscription\_id: “{{ sub\_id }}”

client\_id: “{{ sp }}”

secret: “{{ secret }}”

tenant: “{{ tenant }}”

register: rg\_exists

The full traceback is:

Traceback (most recent call last):

File “/Users/j8683/.ansible/tmp/ansible-tmp-1678891419.194826-50522-78867749364726/AnsiballZ\_azure\_rm\_resourcegroup\_info.py”, line 107, in

\_ansiballz\_main()

File “/Users/j8683/.ansible/tmp/ansible-tmp-1678891419.194826-50522-78867749364726/AnsiballZ\_azure\_rm\_resourcegroup\_info.py”, line 99, in \_ansiballz\_main

invoke\_module(zipped\_mod, temp\_path, ANSIBALLZ\_PARAMS)

File “/Users/j8683/.ansible/tmp/ansible-tmp-1678891419.194826-50522-78867749364726/AnsiballZ\_azure\_rm\_resourcegroup\_info.py”, line 47, in invoke\_module

runpy.run\_module(mod\_name=‘ansible\_collections.azure.azcollection.plugins.modules.azure\_rm\_resourcegroup\_info’, init\_globals=dict(\_module\_fqn=‘ansible\_collections.azure.azcollection.plugins.modules.azure\_rm\_resourcegroup\_info’, \_modlib\_path=modlib\_path),

File “/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py”, line 224, in run\_module

return \_run\_module\_code(code, init\_globals, run\_name, mod\_spec)

File “/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py”, line 96, in \_run\_module\_code

\_run\_code(code, mod\_globals, init\_globals,

File “/opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py”, line 86, in \_run\_code

exec(code, run\_globals)

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/modules/azure\_rm\_resourcegroup\_info.py”, line 235, in

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/modules/azure\_rm\_resourcegroup\_info.py”, line 231, in main

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/modules/azure\_rm\_resourcegroup\_info.py”, line 160, in **init**

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/module\_utils/azure\_rm\_common.py”, line 472, in **init**

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/modules/azure\_rm\_resourcegroup\_info.py”, line 174, in exec\_module

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/modules/azure\_rm\_resourcegroup\_info.py”, line 194, in get\_item

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/module\_utils/azure\_rm\_common.py”, line 1070, in rm\_client

File “/var/folders/51/76dtk91x4wq1lgdndd\_ll6040000gn/T/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload\_52xvp3bz/ansible\_azure.azcollection.azure\_rm\_resourcegroup\_info\_payload.zip/ansible\_collections/azure/azcollection/plugins/module\_utils/azure\_rm\_common.py”, line 920, in get\_mgmt\_svc\_client

TypeError: ResourceManagementClient. **init** () missing 1 required positional argument: ‘credential’.

Not getting what is causing the error as I’m passing the parameters required for service principal auth.

In addition, I tried having a az login task, removing the service principal stuff from the ‘check if the rg already exists’ task. The az login worked… but the task failed with the same error.

This is my version of ansible and ansible-core:

ansible 7.3.0

ansible-core 2.14.3

Here’s more details about my environment:

ansible [core 2.14.3]

config file = None

configured module search path = [‘/Users/j8683/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]

ansible python module location = /Users/j8683/Library/Python/3.9/lib/python/site-packages/ansible

ansible collection location = /Users/j8683/.ansible/collections:/usr/share/ansible/collections

executable location = /Users/j8683/Library/Python/3.9/bin/ansible

python version = 3.9.6 (default, Sep 26 2022, 11:37:49) [Clang 14.0.0 (clang-1400.0.29.202)] (/Library/Developer/CommandLineTools/usr/bin/python3)

jinja version = 3.1.2

libyaml = True

Thanks,

Shawn

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [March 15, 2023, 3:03pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/2 "2023-03-15T15:03:11Z")

</div>

> TypeError: ResourceManagementClient. **init** () missing 1 required positional argument: ‘credential’.

What kind of authentication have you configured?

[https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure\_rm\_resourcegroup\_info\_module.html#ansible-collections-azure-azcollection-azure-rm-resourcegroup-info-module](https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_resourcegroup_info_module.html#ansible-collections-azure-azcollection-azure-rm-resourcegroup-info-module)

Walter

---

<div class="post-metadata">

**Author:** ![callmeshawn](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@callmeshawn](https://forum.ansible.com/u/callmeshawn)\
**Post date:** [March 15, 2023, 4:11pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/3 "2023-03-15T16:11:25Z")

</div>

I have a service principal for authentication.

Based on this bullet:

- To authenticate via service principal, pass subscription\_id, client\_id, secret and tenant or set environment variables AZURE\_SUBSCRIPTION\_ID, AZURE\_CLIENT\_ID, AZURE\_SECRET and AZURE\_TENANT.

My takeaway is that I need to supply the subscription\_id, client\_id, tenant, and secret to tell Ansible that I want to authenticate using service principal.

Since the module accepts subscription\_id, client\_id, tenant, and secret, I’m passing the values to the module, figuring the module will attempt to perform authentication using my service principal.

I’m not getting an authentication failed type of message, so it seems that the module isn’t using the values I’m supplying.  
To test this out, I tried to set auth\_source to “credential\_file”, as I’ve got the parameters required for service principal authentication stored in the default location (~/.azure/credentials); however, it fails the same way, so my guess is the module needs something so that when the constructor gets called … it can create the object; however, I don’t see what I’m missing.

Thanks,

Shawn

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [March 15, 2023, 4:23pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/4 "2023-03-15T16:23:36Z")

</div>

Given how they are presented in all caps and it says “environment variables” then you need to make them ENVIRONMENT variables (ie Linux env vars) – not parameters to the task module.

Walter

---

<div class="post-metadata">

**Author:** ![callmeshawn](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@callmeshawn](https://forum.ansible.com/u/callmeshawn)\
**Post date:** [March 15, 2023, 5:19pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/5 "2023-03-15T17:19:54Z")

</div>

I’m reading that as a way to do it (note the ‘or’…), not the only way to do it…

**or** set environment variables AZURE\_SUBSCRIPTION\_ID, AZURE\_CLIENT\_ID, AZURE\_SECRET and AZURE\_TENANT.

While I can try it out for test purposes, I’m trying to avoid setting the values in environment variables.

I appreciate your feedback.

Shawn

---

<div class="post-metadata">

**Author:** ![callmeshawn](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@callmeshawn](https://forum.ansible.com/u/callmeshawn)\
**Post date:** [March 22, 2023, 7:20pm UTC](https://forum.ansible.com/t/azure-rm-resourcegroup-info-usage-help/37771/6 "2023-03-22T19:20:21Z")

</div>

I opened an issue with the github project.

Short answer, I needed to force upgrade azure/azcollection from 1.14 to 1.15.

For more detail:  
[https://github.com/ansible-collections/azure/issues/1111](https://github.com/ansible-collections/azure/issues/1111)

Thanks,

Shawn
