ansible-collections / azure

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

On-demand backup of azure vm using ansible module provides 400 Bad Request #1698

Open SrinivasanSelvam opened 1 month ago

SrinivasanSelvam commented 1 month ago
SUMMARY

On-demand backup of azure vm using ansible module provides 400 Bad Request

ISSUE TYPE
COMPONENT NAME

azure.azcollection.azure_rm_backupazurevm

ANSIBLE VERSION
ansible [core 2.14.3]
COLLECTION VERSION
azure-cli                         2.56.0 *

core                              2.56.0 *
telemetry                          1.1.0

Extensions:
dataprotection                     0.6.0

Dependencies:
msal                            1.24.0b2
azure-mgmt-resource             23.1.0b2

Python location '/opt/azure-cli/bin/python3'
Extensions directory '/home/deployment/.azure/cliextensions'

Python (Linux) 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
STEPS TO REPRODUCE
Below are the snippets in playbook yaml  values taken from inventory file 
value of state is backup

- name: Trigger an on-demand backup for {{ vm_name }}
  azure.azcollection.azure_rm_backupazurevm:
     resource_group: '{{ resource_group }}'
     recovery_vault_name: '{{ vault_name }}'
     resource_id: '{{ vm_id }}'
     backup_policy_id: '{{ policy_id }}'
     recovery_point_expiry_time: '{{ backup_expiry_time }}'
     state: '{{ state }}'
 register: backup_creation
EXPECTED RESULTS

As per ansible documentation of the azure_rm_backupazurevm moduel, It should trigger ondemand backup of azure vm if state provided as backup

ACTUAL RESULTS
Wednesday 28 August 2024  12:12:01 +0000 (0:00:00.026)       0:00:05.047 ******                                                                              
[WARNING]: Azure API profile latest does not define an entry for GenericRestClient                                                                           
fatal: [<vm_name>]: FAILED! => changed=false 
  msg: 'Error while taking on-demand backup: (<RequestsTransportResponse: 400 Bad Request, Content-Type: application/json>, 400)' 
Fred-sun commented 1 week ago

@SrinivasanSelvam From the error code you returned, it appears that you have a problem in submitting the request parameters. Can you help provide the following information? Because I followed the script below to create, update, stop, and delete azure VM backups without any problems.

First: detailed error information Second: You back up the status of the virtual machine, the version of aze.azcollection you installed.


- name: Fix resource prefix
  ansible.builtin.set_fact:
    recovery_vault_name: 'MyRecoveryVault'
    resource_id: "/subscriptions/xxx/resourceGroups/test_group/providers/Microsoft.Compute/virtualMachines/test"
    backup_policy_id: "/subscriptions/xxx/resourceGroups/v-xisuRG/providers/Microsoft.RecoveryServices/vaults/MyRecoveryVault/backupPolicies/EnhancedPolicy"

- name: Create Azure Recovery Service vault
  azure_rm_recoveryservicesvault:
    resource_group: "{{ resource_group }}"
    name: "{{ recovery_vault_name }}"
    location:  westus2
    state: "present"
  register: output

- name: Enabling/Updating protection for the Azure VM
  azure_rm_backupazurevm:
    resource_group: "{{ resource_group }}"
    recovery_vault_name: "{{ recovery_vault_name }}"
    resource_id: "{{ resource_id }}"
    backup_policy_id: "{{ backup_policy_id }}"
    state: "create"
  register: output

- name: Trigger an on-demand backup for a protected Azure VM
  azure_rm_backupazurevm:
    resource_group: "{{ resource_group }}"
    recovery_vault_name: "{{ recovery_vault_name }}"
    resource_id: "{{ resource_id }}"
    backup_policy_id: "{{ backup_policy_id }}"
    recovery_point_expiry_time: "2025-02-03T05:00:00Z"
    state: "backup"
  register: output

- name: Stop protection but retain existing data
  azure_rm_backupazurevm:
    resource_group: "{{ resource_group }}"
    recovery_vault_name: "{{ recovery_vault_name }}"
    resource_id: "{{ resource_id }}"
    backup_policy_id: "{{ backup_policy_id }}"
    state: "stop"
  register: output

- name: Stop protection and delete data
  azure_rm_backupazurevm:
    resource_group: "{{ resource_group }}"
    recovery_vault_name: "{{ recovery_vault_name }}"
    resource_id: "{{ resource_id }}"
    backup_policy_id: "{{ backup_policy_id }}"
    state: "delete"
  register: output