ansible-collections / azure

Development area for Azure Collections
https://galaxy.ansible.com/azure/azcollection
GNU General Public License v3.0
244 stars 327 forks source link

ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/local/lib/python3.10/dist-packages/azure/mgmt/recoveryservicesbackup/__init__.py) #31993 #1260

Closed markarping closed 10 months ago

markarping commented 11 months ago
SUMMARY

Steps to reproduce the behavior: ansible [core 2.15.4] config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True

python3 --version Python 3.10.12

name: Get Azure VM Info hosts: localhost gather_facts: no # We don't need facts for this playbook tasks: name: Get VM Info azure_rm_virtualmachine_info: resource_group: "{{ Resourcegroupname }}" name: "{{ vmname}}" register: vm_info name: Display VM Info debug: msg: vm_info Expected behavior The full traceback is: Traceback (most recent call last): File "/tmp/ansible_azure_rm_virtualmachine_info_payload_98uulu_q/ansible_azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 275, in from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/local/lib/python3.10/dist-packages/azure/mgmt/recoveryservicesbackup/init.py)

ISSUE TYPE

ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/local/lib/python3.10/dist-packages/azure/mgmt/recoveryservicesbackup/init.py) #31993

COMPONENT NAME
ANSIBLE VERSION

ansible [core 2.15.4] config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.10/dist-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible python version = 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] (/usr/bin/python3) jinja version = 3.1.2 libyaml = True

``

COLLECTION VERSION

# /usr/lib/python3/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 1.3.6

# /usr/local/lib/python3.10/dist-packages/ansible_collections
Collection        Version
----------------- -------
community.general 7.4.0
CONFIGURATION
 ansible-config dump --only-changed
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/home/ansible/inventory/inv']
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = ['/home/ansible/roles']
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
INTERPRETER_PYTHON(/etc/ansible/ansible.cfg) = /usr/bin/python3.10
OS / ENVIRONMENT

cat /etc/os-release PRETTY_NAME="Ubuntu 22.04.3 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.3 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy

*-firmware description: BIOS vendor: American Megatrends Inc. physical id: 0 version: 090008 date: 12/07/2018 size: 64KiB capacity: 256KiB

STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS

The full traceback is: Traceback (most recent call last): File "/tmp/ansible_azure_rm_virtualmachine_info_payload_fb_d5cd6/ansible_azure_rm_virtualmachine_info_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 275, in from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/local/lib/python3.10/dist-packages/azure/mgmt/recoveryservicesbackup/init.py)

"msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on ansiblekmtl's Python /usr/bin/python3. 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" }

markarping commented 11 months ago

Can you update the bug fix solutions to fix this issue.

GaretJax commented 11 months ago

https://github.com/Azure/azure-sdk-for-python/issues/28757#issuecomment-1448729884 this fix works for me.

https://github.com/ansible-collections/azure/blob/86e0f070372400d6b50ce66f6f78542b18fd8e38/plugins/module_utils/azure_rm_common.py#L275-L276

-from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
-import azure.mgmt.recoveryservicesbackup.models as RecoveryServicesBackupModels
+from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
+import azure.mgmt.recoveryservicesbackup.activestamp.models as RecoveryServicesBackupModels
Fred-sun commented 10 months ago

@GaretJax @markarping The above prompt appears because the version you installed does not match the version specified for your requirements. The version now required is azure-mgmt-recoveryservicesbackup==3.0.0. I recommend you try this version. Thank you!

eliassal commented 9 months ago

@GaretJax I had azure-mgmt-recoveryservicesbackup 7.0.0 which I removed when I trtied to install 3.0.0, here is the output

pip install azure-mgmt-recoveryservicesbackup version==3.0.0 Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: azure-mgmt-recoveryservicesbackup in /usr/lib/python3.11/site-packages (6.0.0) ERROR: Could not find a version that satisfies the requirement version==3.0.0 (from versions: 0.1.0, 0.1.1) ERROR: No matching distribution found for version==3.0.0

eliassal commented 9 months ago

when I tried agai as now it is version 6.0.0 I got the sasme result

The full traceback is: Traceback (most recent call last): File "/tmp/ansible_azure_rm_virtualnetwork_payload_nuo_y727/ansible_azure_rm_virtualnetwork_payload.zip/ansible_collections/azure/azcollection/plugins/module_utils/azure_rm_common.py", line 264, in from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient ImportError: cannot import name 'RecoveryServicesBackupClient' from 'azure.mgmt.recoveryservicesbackup' (/usr/lib/python3.11/site-packages/azure/mgmt/recoveryservicesbackup/init.py) fatal: [localhost]: FAILED! => { "changed": false, "invocation": { "module_args": { "ad_user": null, "address_prefixes": "10.10.0.0/16", "address_prefixes_cidr": [ "10.10.0.0/16" ], "adfs_authority_url": null, "api_profile": "latest", "append_tags": true, "auth_source": "auto", "cert_validation_mode": null, "client_id": null, "cloud_environment": "AzureCloud", "dns_servers": null, "flow_timeout_in_minutes": null, "location": null, "log_mode": null, "log_path": null, "name": "awesomevnet", "password": null, "profile": null, "purge_address_prefixes": false, "purge_dns_servers": false, "resource_group": "manageazureansible", "secret": null, "state": "present", "subscription_id": null, "tags": null, "tenant": null, "thumbprint": null, "x509_certificate_path": null } }, "msg": "Failed to import the required Python library (ansible[azure] (azure >= 2.0.0)) on puppetmaster29's Python /usr/bin/python3. 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"

Fred-sun commented 9 months ago

@eliassal This is because there is a problem with your environment after you reinstall it. Can you reconfigure the environment and try again? Please refer to the following order(https://github.com/ansible-collections/azure). Thank you!


pip3 install ansible[azure]  --- Install ansible
ansible-galaxy collection install azure.azcollection  ---- Install Azure Collections
pip3 install -r ~/.ansible/collections/ansible_collections/azure/azcollection/requirements-azure.txt ---- install dependence
eliassal commented 9 months ago

@Fred-sun Thanks, I followed the exact same instructions, rerun ansible-playbook I got

ERROR! couldn't resolve module/action 'azure_rm_virtualnetwork'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/home/salam/projects/content-managing-azure-resources-with-ansible/deploying-azure-virtual-machines/vm.yml': line 23, column 7, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

tasks:

  • name: Create virtual network ^ here
eliassal commented 9 months ago

@Fred-sun for your covenienance, here is the ansible playbook

---
- name: Create Azure VM
  hosts: localhost
  connection: local

  collections:
    - azure.azcollection

  vars_prompt:
    - name: password
      prompt: "Enter local administrator password"

  vars:
    resource_group_name: manageazureansible
    vm_name: awesomevm1
    vnet_name: awesomevnet
    subnet_name: awesomesubnet1
    public_ip_name: awesomepublicip1
    security_group_name: awesomesecgroup1
    network_interface_name: awesomenic1

  tasks:
    - name: Create virtual network
      azure_rm_virtualnetwork:
        resource_group: "{{ resource_group_name }}"
        name: "{{ vnet_name }}"
        address_prefixes: "10.10.0.0/16"

    - name: Add subnet
      azure_rm_subnet:
        resource_group: "{{ resource_group_name }}"
        name: "{{ subnet_name }}"
        address_prefix: "10.10.0.0/24"
        virtual_network: "{{ vnet_name }}"

    - name: Create public ip
      azure_rm_publicipaddress:
        resource_group: "{{ resource_group_name }}"
        allocation_method: Static
        name: "{{ public_ip_name }}"

    - name: Create security group that allows RDP
      azure_rm_securitygroup:
        resource_group: "{{ resource_group_name }}"
        name: "{{ security_group_name }}"
        rules:
          - name: 'allow_rdp'
            protocol: Tcp
            destination_port_range: 3389
            access: Allow
            priority: 1001
            direction: Inbound
          - name: 'allow_web_traffic'
            protocol: Tcp
            destination_port_range:
              - 80
              - 443
            access: Allow
            priority: 1002
            direction: Inbound
          - name: 'allow_powershell_remoting'
            protocol: Tcp
            destination_port_range: 
              - 5985
              - 5986
            access: Allow
            priority: 1003
            direction: Inbound

    - name: Create NIC
      azure_rm_networkinterface:
        resource_group: "{{ resource_group_name }}"
        name: "{{ network_interface_name }}"
        virtual_network: "{{ vnet_name }}"
        subnet: "{{ subnet_name }}"
        public_ip_name: "{{ public_ip_name }}"
        security_group: "{{ security_group_name }}"

    - name: Create virtual machine
      azure_rm_virtualmachine:
        resource_group: "{{ resource_group_name }}"
        name: "{{ vm_name }}"
        vm_size: Standard_DS1_v2
        managed_disk_type: Standard_LRS
        admin_username: awesomeadmin
        admin_password: "{{ password }}"
        network_interfaces: "{{ network_interface_name }}"
        os_type: Windows
        image:
            offer: WindowsServer
            publisher: MicrosoftWindowsServer
            sku: 2019-Datacenter
            version: latest
      no_log: true
eliassal commented 9 months ago

@Fred-sun and here ius the output of ansible-galaxy collection list

# /home/salam/.ansible/collections/ansible_collections
Collection                    Version
----------------------------- -------
azure.azcollection            1.19.0

# /home/salam/.local/lib/python3.10/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    6.5.0
ansible.netcommon             5.3.0
ansible.posix                 1.5.4
ansible.utils                 2.11.0
ansible.windows               1.14.0
arista.eos                    6.2.1
awx.awx                       22.7.0
azure.azcollection            1.19.0
check_point.mgmt              5.1.1
chocolatey.chocolatey         1.5.1
cisco.aci                     2.8.0
cisco.asa                     4.0.3
cisco.dnac                    6.7.6
cisco.intersight              1.0.27
cisco.ios                     4.6.1
cisco.iosxr                   5.0.3
cisco.ise                     2.5.16
cisco.meraki                  2.16.13
cisco.mso                     2.5.0
cisco.nso                     1.0.3
cisco.nxos                    4.4.0
cisco.ucs                     1.10.0
cloud.common                  2.1.4
cloudscale_ch.cloud           2.3.1
community.aws                 6.4.0
community.azure               2.0.0
community.ciscosmb            1.0.7
community.crypto              2.16.0
community.digitalocean        1.24.0
community.dns                 2.6.3
community.docker              3.4.10
community.fortios             1.0.0
community.general             7.5.1
community.google              1.0.0
community.grafana             1.6.1
community.hashi_vault         5.0.1
community.hrobot              1.8.1
community.libvirt             1.3.0
community.mongodb             1.6.3
community.mysql               3.8.0
community.network             5.0.2
community.okd                 2.3.0
community.postgresql          2.4.3
community.proxysql            1.5.1
community.rabbitmq            1.2.3
community.routeros            2.10.0
community.sap                 1.0.0
community.sap_libs            1.4.1
community.skydive             1.0.0
community.sops                1.6.7
community.vmware              3.11.1
community.windows             1.13.0
community.zabbix              2.1.0
containers.podman             1.11.0
cyberark.conjur               1.2.2
cyberark.pas                  1.0.23
dellemc.enterprise_sonic      2.2.0
dellemc.openmanage            7.6.1
dellemc.powerflex             1.9.0
dellemc.unity                 1.7.1
f5networks.f5_modules         1.27.0
fortinet.fortimanager         2.3.0
fortinet.fortios              2.3.4
frr.frr                       2.0.2
gluster.gluster               1.0.2
google.cloud                  1.2.0
grafana.grafana               2.2.3
hetzner.hcloud                1.16.0
hpe.nimble                    1.1.4
ibm.qradar                    2.1.0
ibm.spectrum_virtualize       1.12.0
ibm.storage_virtualize        2.1.0
infinidat.infinibox           1.3.12
infoblox.nios_modules         1.5.0
inspur.ispim                  1.3.0
inspur.sm                     2.3.0
junipernetworks.junos         5.3.0
kubernetes.core               2.4.0
lowlydba.sqlserver            2.2.2
microsoft.ad                  1.3.0
netapp.aws                    21.7.1
netapp.azure                  21.10.1
netapp.cloudmanager           21.22.1
netapp.elementsw              21.7.0
netapp.ontap                  22.8.0
netapp.storagegrid            21.11.1
netapp.um_info                21.8.1
netapp_eseries.santricity     1.4.0
netbox.netbox                 3.15.0
ngine_io.cloudstack           2.3.0
ngine_io.exoscale             1.1.0
ngine_io.vultr                1.1.3
openstack.cloud               2.1.0
openvswitch.openvswitch       2.1.1
ovirt.ovirt                   3.2.0
purestorage.flasharray        1.21.0
purestorage.flashblade        1.14.0
purestorage.fusion            1.6.0
sensu.sensu_go                1.14.0
servicenow.servicenow         1.0.6
splunk.es                     2.1.0
t_systems_mms.icinga_director 1.33.1
telekom_mms.icinga_director   1.34.1
theforeman.foreman            3.14.0
vmware.vmware_rest            2.3.1
vultr.cloud                   1.10.0
vyos.vyos                     4.1.0
wti.remote                    1.0.5
eliassal commented 9 months ago

And here is the list for the command

pip list |grep -E az\|ans

ansible 8.6.0 ansible-core 2.15.6 azure-cli-core 2.34.0 azure-cli-telemetry 1.0.6 azure-common 1.1.11 azure-containerregistry 1.1.0 azure-core 1.28.0 azure-graphrbac 0.61.1 azure-identity 1.7.0 azure-iot-hub 2.6.1 azure-keyvault 4.2.0 azure-keyvault-certificates 4.7.0 azure-keyvault-keys 4.8.0 azure-keyvault-secrets 4.7.0 azure-mgmt-apimanagement 3.0.0 azure-mgmt-authorization 2.0.0 azure-mgmt-automation 1.0.0 azure-mgmt-batch 16.2.0 azure-mgmt-cdn 11.0.0 azure-mgmt-compute 26.1.0 azure-mgmt-containerinstance 9.0.0 azure-mgmt-containerregistry 9.1.0 azure-mgmt-containerservice 20.0.0 azure-mgmt-core 1.3.0 azure-mgmt-cosmosdb 6.4.0 azure-mgmt-datafactory 2.0.0 azure-mgmt-datalake-store 1.0.0 azure-mgmt-devtestlabs 9.0.0 azure-mgmt-dns 8.0.0 azure-mgmt-eventhub 10.1.0 azure-mgmt-hdinsight 9.0.0 azure-mgmt-iothub 2.2.0 azure-mgmt-keyvault 10.0.0 azure-mgmt-loganalytics 12.0.0 azure-mgmt-managedservices 6.0.0 azure-mgmt-managementgroups 1.0.0 azure-mgmt-marketplaceordering 1.1.0 azure-mgmt-monitor 3.0.0 azure-mgmt-network 19.1.0 azure-mgmt-notificationhubs 7.0.0 azure-mgmt-nspkg 2.0.0 azure-mgmt-privatedns 1.0.0 azure-mgmt-rdbms 10.0.0 azure-mgmt-recoveryservices 2.0.0 azure-mgmt-recoveryservicesbackup 3.0.0 azure-mgmt-redis 13.0.0 azure-mgmt-resource 21.1.0 azure-mgmt-search 8.0.0 azure-mgmt-servicebus 7.1.0 azure-mgmt-sql 3.0.1 azure-mgmt-storage 19.0.0 azure-mgmt-trafficmanager 1.0.0b1 azure-mgmt-web 6.1.0 azure-nspkg 2.0.0 azure-storage-blob 12.11.0 lazr.restfulclient 0.14.4 lazr.uri 1.0.6 msrestazure 0.6.4

Fred-sun commented 9 months ago

@markarping From the above error, you installed, during the execution, you did not find the installed file, so the error. The cause of the error is again in your environment, your playbook is fine. Thank you!


![image](https://github.com/ansible-collections/azure/assets/37327967/0a888bfc-885f-4aea-b86b-865b14f64ce8)
eliassal commented 9 months ago

So what is the error please? I am not able to understand what you mean by

you installed, during the execution, you did not find the installed file, so the error...

I had no errors during install. So, OK, what should I do as I followed all instructions, where can I find the installed file? and if it is installed why ansible is not able to see it or calling it.