Azure.azcollection:2.6.0 still using az-cli to authenticate even when using service principal way of doing it

we are trying to upload a txt file to a azure blob storage using ansible playbook.
We are using azure.azcollection.azure_rm_storageblob package to perform the upload.
My azure.azcollection version is 2.6.0

auto@32fb1b2fe9a1:/$ ansible-galaxy collection list

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection Version
----------------------------- -------
azure.azcollection 2.6.0

and ansibel version is ansible-core==2.15.5

the ansible playbook content is


- name: Upload a test file to Azure Blob
** hosts: localhost**
** tasks:**
** - name: Upload a test file to Azure Blob**
** azure.azcollection.azure_rm_storageblob:**
** subscription_id: “{{ lookup(‘env’, ‘AZURE_SUBSCRIPTION_ID’) }}”**
** client_id: “{{ lookup(‘env’, ‘AZURE_CLIENT_ID’) }}”**
** secret: “{{ lookup(‘env’, ‘AZURE_SECRET’) }}”**
** tenant: “{{ lookup(‘env’, ‘AZURE_TENANT’) }}”**
** storage_account_name: “your_storage_account_name”**
** resource_group: “your_resource_group”**
** container: “your_container_name”**
** blob: “test_blob_name”**
** src: “/path/to/your/local_file.txt”**
** state: present**

we have exported the env var as
export AZURE_SUBSCRIPTION_ID=“your_subscription_id”
export AZURE_CLIENT_ID=“your_client_id”
export AZURE_SECRET=“your_secret”
export AZURE_TENANT=“your_tenant_id”

but still getting belwo error where it is expecting azure-cli , which should not be rthe case as per documentation. It should use service principal for authentication and not azure cli.

err:
auto@d306e2ceedee:~$ ansible-playbook test.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Test Azure Blob Upload] *************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************
ok: [localhost]

TASK [Upload a test file to Azure Blob] ***************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’
fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on d306e2ceedee’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

PLAY RECAP ********************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

verbose stacktrace

The full traceback is:
Traceback (most recent call last):
File “/tmp/ansible_azure.azcollection.azure_rm_storageblob_payload_p5jrzqbn/ansible_azure.azcollection.azure_rm_storageblob_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py”, line 243, in
from azure.cli.core import cloud as azure_cloud
ModuleNotFoundError: No module named ‘azure.cli’

EDIT PART


My oppologies for the confusion here.
While capturing the details by mistake took Screen shots from two different conatiners but they were both spinned up with same image.
However i am attaching the details again as the problem is still persisting.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

Hii

mayank_gupta
September 6 |

  • | - |

we are trying to upload a txt file to a azure blob storage using ansible playbook.
We are using azure.azcollection.azure_rm_storageblob package to perform the upload.
My azure.azcollection version is 2.6.0

auto@32fb1b2fe9a1:/$ ansible-galaxy collection list

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection Version
----------------------------- -------
azure.azcollection 2.6.0

That is on host 32fb1b2fe9a1.

TASK [Upload a test file to Azure Blob] ***************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’
fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on d306e2ceedee’s Python /usr/local/bin/python.

While the reported error is on host d306e2ceedee.
So, you should make sure to install it on host d306e2ceedee.

Dick

Hi @dnmvisser .
Sorry for the confusion, My appologies i might have capture the error logs on different containers but issue is there. I am putting the error SS again here.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

Hi @dnmvisser
Thanks for reply.
My appologies for the confusion. The capture was done from 2 different containers but with same image. However i am adding the details again from same container and the problem poersists.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

Hi @dnmvisser
Thanks for the reply.
My oppologies for the confusion here.
While capturing the details by mistake took Screen shots from two different conatiners but they were both spinned up with same image.
However i am attaching the details again as the problem is still persisting.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

Hi @dnmvisser
Thanks for the reply.
My oppologies for the confusion here.
While capturing the details by mistake took Screen shots from two different conatiners but they were both spinned up with same image.
However i am attaching the details again as the problem is still persisting.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

Hi @dnmvisser
Thanks for the reply.
My oppologies for the confusion here.
While capturing the details by mistake took Screen shots from two different conatiners but they were both spinned up with same image.
However i am attaching the details again as the problem is still persisting.

autotron@c08393297018:~$ ansible-galaxy collection list

/usr/local/lib/python3.9/site-packages/ansible_collections

Collection Version


amazon.aws 6.5.0
ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0
ansible.windows 1.14.0
arista.eos 6.1.2
awx.awx 22.7.0
azure.azcollection 2.6.0

autotron@c08393297018:~$ ansible-playbook test.yml

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Upload file to Azure Blob] **********************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************

ok: [localhost]

TASK [Upload file to Azure Blob] **********************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

fatal: [localhost]: FAILED! => {“changed”: false, “msg”: “Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on c08393297018’s Python /usr/local/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter”}

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named ‘azure.cli’

I see azure-cli-core in the Python requirements for the collection azure/requirements.txt at v2.6.0 · ansible-collections/azure · GitHub. All of the requirements need to be installed on the remote host. It looks like /usr/local/bin/python is the Python executable Ansible is using on the remote, so you’ll need to install the requirements to the same Python: /usr/local/bin/python -m pip install ....