Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure_rm_account_info dont work since v2 #1413

Closed
ebuildy opened this issue Jan 18, 2024 · 7 comments
Closed

azure_rm_account_info dont work since v2 #1413

ebuildy opened this issue Jan 18, 2024 · 7 comments
Labels
bug Something isn't working closed It has been fixed has_pr PR fixes have been made medium_priority Medium priority

Comments

@ebuildy
Copy link

ebuildy commented Jan 18, 2024

SUMMARY

task:

    - name: Get facts for current logged in user
      azure.azcollection.azure_rm_account_info:
      register: azure_account

throw error The error was: TypeError: Session.request() got an unexpected keyword argument 'claims'

ISSUE TYPE
  • Bug Report
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.16.2]
  config file = None
  configured module search path = ['/Users/tdecaux/.ansible/venv2/amsible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/tdecaux/.ansible/venv2/amsible/collections:/usr/share/ansible/collections
  executable location = /Users/tdecaux/.ansible/venv2/bin/ansible
  python version = 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/Users/tdecaux/.ansible/venv2/bin/python3.11)
  jinja version = 3.1.3
  libyaml = True
COLLECTION VERSION

v2 (work with v1.19.0)

CONFIGURATION

OS / ENVIRONMENT
STEPS TO REPRODUCE
python3 -m venv ~/.ansible/venv2
source ~/.ansible/venv2/bin/activate

ansible-galaxy collection install azure.azcollection # version 2
# install azcollection 
pip install -r requirements-azure.tx
EXPECTED RESULTS
ACTUAL RESULTS

throw error The error was: TypeError: Session.request() got an unexpected keyword argument 'claims'

  File "/var/folders/l0/4hldrgzs74s5wgjtnscj5k2m0000gq/T/ansible_azure.azcollection.azure_rm_account_info_payload_rjeoflfh/ansible_azure.azcollection.azure_rm_account_info_payload.zip/ansible_collections/azure/azcollection/plugins/modules/azure_rm_account_info.py", line 204, in getAccount
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msgraph/generated/users/item/user_item_request_builder.py", line 156, in get
    return await self.request_adapter.send_async(request_info, User, error_mapping)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 178, in send_async
    response = await self.get_http_response_message(request_info, parent_span)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 521, in get_http_response_message
    await self._authentication_provider.authenticate_request(
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/kiota_abstractions/authentication/base_bearer_token_authentication_provider.py", line 50, in authenticate_request
    token = await self.access_token_provider.get_authorization_token(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/kiota_authentication_azure/azure_identity_access_token_provider.py", line 103, in get_authorization_token
    result = self._credentials.get_token(*self._scopes, claims=decoded_claim)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/azure/cli/core/auth/credential_adaptor.py", line 65, in get_token
    token, _ = self._get_token(scopes, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/azure/cli/core/auth/credential_adaptor.py", line 38, in _get_token
    token = self._credential.get_token(*scopes, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/azure/cli/core/auth/msal_authentication.py", line 60, in get_token
    result = self.acquire_token_silent_with_error(list(scopes), self._account, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/application.py", line 1269, in acquire_token_silent_with_error
    return _clean_up(self._acquire_token_silent_with_error(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/application.py", line 1292, in _acquire_token_silent_with_error
    result = self._acquire_token_silent_from_cache_and_possibly_refresh_it(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/application.py", line 1422, in _acquire_token_silent_from_cache_and_possibly_refresh_it
    result = self._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/application.py", line 1483, in _acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family
    last_resp = at = self._acquire_token_silent_by_finding_specific_refresh_token(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/application.py", line 1533, in _acquire_token_silent_by_finding_specific_refresh_token
    response = client.obtain_token_by_refresh_token(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/oauth2cli/oauth2.py", line 830, in obtain_token_by_refresh_token
    resp = super(Client, self).obtain_token_by_refresh_token(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/oauth2cli/oauth2.py", line 262, in obtain_token_by_refresh_token
    return self._obtain_token("refresh_token", data=data, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/oauth2cli/oidc.py", line 116, in _obtain_token
    ret = super(Client, self)._obtain_token(grant_type, *args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/oauth2cli/oauth2.py", line 771, in _obtain_token
    resp = super(Client, self)._obtain_token(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/oauth2cli/oauth2.py", line 234, in _obtain_token
    resp = (post or self._http_client.post)(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/individual_cache.py", line 269, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/msal/individual_cache.py", line 269, in wrapper
    value = function(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tdecaux/.ansible/venv2/lib/python3.11/site-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Session.request() got an unexpected keyword argument 'claims'
Related

#1387

@Fred-sun Fred-sun added medium_priority Medium priority work in In trying to solve, or in working with contributors labels Jan 19, 2024
@radsto
Copy link

radsto commented Feb 23, 2024

Bump

@Fred-sun
Copy link
Collaborator

@ebuildy @radsto azure_rm_account_info.py is used to access login account information, so when using this module, you need to have az login, and then use the cli credentials(auth_source: cli) to get login account information through the 'auth_source' setting. After migrating to msgraph earlier, you need to make a few minor changes, see https://github.com/ansible-collections/azure/pull/1510.。 Thank you!

- name: Get account facts
  azure.azcollection.azure_rm_account_info:
    auth_source: cli
  register: output
- debug:
    var: output

Return:
"output": {
"account_info": {
"environmentName": "AzureCloud",
"homeTenantId": "xxxxxxxxxx",
"id": "xxxxxxxxxxxxxxxxxxxxxxxxx",
"managedByTenants": [],
"name": "Visual Studio Enterprise",
"state": "Enabled",
"tenantId": "8xxxxxxxxxxxxxxxxxxxxxxx",
"user": {
"name": "xxxxxxxxxxxxxxxxxx",
"type": "Member"
}
},

@Fred-sun Fred-sun added the has_pr PR fixes have been made label Mar 25, 2024
@Fred-sun
Copy link
Collaborator

Fixed by #1510

@Fred-sun Fred-sun added bug Something isn't working and removed work in In trying to solve, or in working with contributors labels Mar 25, 2024
@radsto
Copy link

radsto commented Mar 25, 2024

Thanks for the workaround, I will test this !

@Fred-sun
Copy link
Collaborator

Thanks for the workaround, I will test this !

Any feedback?

@radsto
Copy link

radsto commented Mar 26, 2024

@Fred-sun

I have cloned your branch with the fix and ran the following playbook

- hosts: localhost
  tasks:
    - name: Get facts for current logged in user
      azure.azcollection.azure_rm_account_info:
        auth_source: cli
      register: azure_account

    - debug:
        var: azure_account

It passes fine :

image

Thanks for your fix and wish you a nice day !

@Fred-sun
Copy link
Collaborator

@ebuildy @radsto The related PR has been merged and I will close this issue. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working closed It has been fixed has_pr PR fixes have been made medium_priority Medium priority
Projects
None yet
Development

No branches or pull requests

3 participants