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

Resolved #234 #248

Merged
merged 18 commits into from
Sep 9, 2020
Merged

Resolved #234 #248

merged 18 commits into from
Sep 9, 2020

Conversation

suyeb786
Copy link
Contributor

@suyeb786 suyeb786 commented Sep 7, 2020

SUMMARY

This module will introduce a backup feature for azure VM and will be offering feature listed below

Enabling protection for the Azure VM
Trigger an on-demand backup for a protected Azure VM
Modify the backup configuration for a protected Azure VM
Stop protection but retain existing data
Stop protection and delete data

Fixes #234

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

azure_rm_backupazurevm
azure_rm_backupazurevm_info

ADDITIONAL INFORMATION

@suyeb786
Copy link
Contributor Author

suyeb786 commented Sep 7, 2020

Hi @Fred-sun,
My module is ready for Azure VM backup(#234).
Could you please review it.

@Fred-sun Fred-sun added medium_priority Medium priority new_module_pr Add new modules work in In trying to solve, or in working with contributors labels Sep 8, 2020
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm_info.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm_info.py Outdated Show resolved Hide resolved
plugins/modules/azure_rm_backupazurevm_info.py Outdated Show resolved Hide resolved
@suyeb786
Copy link
Contributor Author

suyeb786 commented Sep 8, 2020

Hi @Fred-sun,
Thank you for reviewing the module
The code is adjusted with the latest comments.

@Fred-sun
Copy link
Collaborator

Fred-sun commented Sep 8, 2020

Hi @Fred-sun,
Thank you for reviewing the module
The code is adjusted with the latest comments.

Hi @suyeb786 I'm testing, and will feedback to you! Thank you very much!

@Fred-sun
Copy link
Collaborator

Fred-sun commented Sep 8, 2020

Hi @suyeb786 How did you get the backup_policy_id?

Suggestion change:  
    1. Rename *.yaml to .yml
    2. Add the module name azure_rm_backupazurevm in ./pr-pipeline.yml
    3 Update main.yml' "backup_policy_id" to "{{ backup_policy_id }}"




pr-pipelines.yml Outdated Show resolved Hide resolved
@Fred-sun
Copy link
Collaborator

Fred-sun commented Sep 8, 2020

Update **tests/integration/targets/azure_rm_backupazurevm/meta/main.yaml ** to **tests/integration/targets/azure_rm_backupazurevm/meta/main.yml **

@suyeb786
Copy link
Contributor Author

suyeb786 commented Sep 8, 2020

Hi @Fred-sun,

In the recovery service vault, we have provision for creating backup policies.
Also, there is a default policy that is available by default when we create a recovery service vault in azure.

"policyId": "/subscriptions/<subscription_id>/resourceGroups/<resource_group_name>/providers/microsoft.recoveryservices/vaults/<vault_name>/backupPolicies/DefaultPolicy"

replace <subscription_id> ->> with subsription id
replace <resource_group_name> ->> with resouce group name
replace <vault_name> >> with your recovery vault name

eg.

"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testVaultRG/providers/microsoft.recoveryservices/vaults/testVault/backupPolicies/DefaultPolicy"

@Fred-sun
Copy link
Collaborator

Fred-sun commented Sep 8, 2020

It is recommended to update tasks as follows:

- name: Fix resource prefix
  set_fact:
    resource_group: 'MyResourceGroup'
    recovery_vault_name: 'MyRecoveryVault'
    resource_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM"
    backup_policy_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/microsoft.recoveryservices/vaults/testVault/backupPolicies/ProdPolicy"

- 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: Assert that output has changed
  assert:
    that:
      - output.changed
      
- 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 }}"
    state: "backup"
  register: output

- name: Assert that output has changed
  assert:
    that:
      - output.changed

- 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: Assert that output has changed
  assert:
    that:
      - output.changed
      
- name: Get backup azure vm info
  azure_rm_backupazurevm_info:
    resource_group: "{{ resource_group }}"
    recovery_vault_name: "{{ recovery_vault_name }}"
    resource_id: "{{ resource_id }}"
  register: output

- name: Assert that output has changed
  assert:
    that:
      - output.response.id != None
      - output.response.name != None
   
- 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

- name: Assert that output has changed
  assert:
    that:
      - output.changed
  

@Fred-sun
Copy link
Collaborator

Fred-sun commented Sep 9, 2020

@suyeb786 Thank you for your supportive response. Basically, it has been changed almost!

@suyeb786
Copy link
Contributor Author

suyeb786 commented Sep 9, 2020

Hello @Fred-sun ,

Thank you for your help and quick reviews, with your help I understand all core requirements for the ansible azure modules and it will be very helpful for me for feature development.

@haiyuazhang haiyuazhang merged commit 6c9cd41 into ansible-collections:dev Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium_priority Medium priority new_module_pr Add new modules work in In trying to solve, or in working with contributors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Back up an Azure VM using Azure Backup
3 participants