Skip to content

Commit

Permalink
Adding protection policies examples file
Browse files Browse the repository at this point in the history
  • Loading branch information
george-ghawali committed Jan 9, 2025
1 parent a5a6d5f commit 3f96326
Showing 1 changed file with 295 additions and 0 deletions.
295 changes: 295 additions & 0 deletions examples/protection_policies_v2/protection_policies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
---
- name: Protection policies playbook
hosts: localhost
gather_facts: false
module_defaults:
group/nutanix.ncp.ntnx:
nutanix_host: <pc_ip>
nutanix_username: <user>
nutanix_password: <pass>
validate_certs: false
tasks:
- name: Setting Random name and labels
ansible.builtin.set_fact:
random_name: "{{query('community.general.random_string',numbers=false, special=false,length=12)[0]}}"
label1: "{{query('community.general.random_string',numbers=false, special=false,length=12)[0]}}"
label2: "{{query('community.general.random_string',numbers=false, special=false,length=12)[0]}}"
todelete: []

- name: Setting Variables
ansible.builtin.set_fact:
replication_location_1:
label: "ansible-test-label1"
domain_manager_ext_id: "425cd2d4-32e0-4c2d-a026-31d81fa4c805"
is_primary: true
replication_sub_location: null
replication_location_2:
label: "ansible-test-label2"
domain_manager_ext_id: "b3a6932b-f64e-49ee-924d-c5a5b8ce2f3f"
is_primary: false
replication_sub_location: null
replication_location_1_updated:
label: "ansible-test-label1_updated"
domain_manager_ext_id: "425cd2d4-32e0-4c2d-a026-31d81fa4c805"
is_primary: true
replication_sub_location:
replication_location_2_updated:
label: "ansible-test-label2_updated"
domain_manager_ext_id: "b3a6932b-f64e-49ee-924d-c5a5b8ce2f3f"
is_primary: false
replication_sub_location:
replication_configuration_linear_1:
source_location_label: "ansible-test-label1"
remote_location_label: "ansible-test-label2"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 3600
retention:
local: 1
remote: 1
start_time: "15h:19m"
sync_replication_auto_suspend_timeout_seconds: 300
replication_configuration_linear_2:
source_location_label: "ansible-test-label2"
remote_location_label: "ansible-test-label1"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 3600
retention:
local: 1
remote: 1
start_time: "15h:19m"
sync_replication_auto_suspend_timeout_seconds: 300
replication_configuration_linear_1_updated:
source_location_label: "ansible-test-label1_updated"
remote_location_label: "ansible-test-label2_updated"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 7200
retention:
local: 2
remote: 2
start_time: "16h:12m"
sync_replication_auto_suspend_timeout_seconds: 90
replication_configuration_linear_2_updated:
source_location_label: "ansible-test-label2_updated"
remote_location_label: "ansible-test-label1_updated"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 7200
retention:
local: 2
remote: 2
start_time: "16h:12m"
sync_replication_auto_suspend_timeout_seconds: 90
replication_configuration_auto_1:
source_location_label: "ansible-test-label1"
remote_location_label: "ansible-test-label2"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 3600
retention:
local:
snapshot_interval_type: "DAILY"
frequency: 1
remote:
snapshot_interval_type: "DAILY"
frequency: 1
start_time: "15h:19m"
sync_replication_auto_suspend_timeout_seconds: 300
replication_configuration_auto_2:
source_location_label: "ansible-test-label2"
remote_location_label: "ansible-test-label1"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 3600
retention:
local:
snapshot_interval_type: "DAILY"
frequency: 1
remote:
snapshot_interval_type: "DAILY"
frequency: 1
start_time: "15h:19m"
sync_replication_auto_suspend_timeout_seconds: 300
replication_configuration_auto_1_updated:
source_location_label: "ansible-test-label1_updated"
remote_location_label: "ansible-test-label2_updated"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 7200
retention:
local:
snapshot_interval_type: "DAILY"
frequency: 2
remote:
snapshot_interval_type: "DAILY"
frequency: 2
start_time: "13h:08m"
sync_replication_auto_suspend_timeout_seconds: 90
replication_configuration_auto_2_updated:
source_location_label: "ansible-test-label2_updated"
remote_location_label: "ansible-test-label1_updated"
schedule:
recovery_point_type: "CRASH_CONSISTENT"
recovery_point_objective_time_seconds: 7200
retention:
local:
snapshot_interval_type: "DAILY"
frequency: 2
remote:
snapshot_interval_type: "DAILY"
frequency: 2
start_time: "13h:08m"
sync_replication_auto_suspend_timeout_seconds: 90
category_ext_id_1: "bbc3555a-5478-1122-4411-bfff196e84e4"
category_ext_id_2: "e4bda88f-9632-3322-2233-2c0bb00d923d"

- name: Create linear retention protection policy
nutanix.ncp.ntnx_protection_policies_v2:
name: "ansible-name-linear-{{random_name}}"
description: "ansible-description-linear-{{random_name}}"
replication_locations:
- "{{ replication_location_1 }}"
- "{{ replication_location_2 }}"
replication_configurations:
- source_location_label: "{{ replication_configuration_linear_1.source_location_label }}"
remote_location_label: "{{ replication_configuration_linear_1.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_linear_1.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_linear_1.schedule.recovery_point_objective_time_seconds | int }}"
retention:
linear_retention:
local: "{{ replication_configuration_linear_1.schedule.retention.local }}"
remote: "{{ replication_configuration_linear_1.schedule.retention.remote }}"
start_time: "{{ replication_configuration_linear_1.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds: "{{ replication_configuration_linear_1.schedule.sync_replication_auto_suspend_timeout_seconds }}"
- source_location_label: "{{ replication_configuration_linear_2.source_location_label }}"
remote_location_label: "{{ replication_configuration_linear_2.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_linear_2.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_linear_2.schedule.recovery_point_objective_time_seconds | int }}"
retention:
linear_retention:
local: "{{ replication_configuration_linear_2.schedule.retention.local }}"
remote: "{{ replication_configuration_linear_2.schedule.retention.remote }}"
start_time: "{{ replication_configuration_linear_2.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds: "{{ replication_configuration_linear_2.schedule.sync_replication_auto_suspend_timeout_seconds }}"
category_ids:
- "{{category_ext_id_1}}"
register: result

- name: Set protection policy ext id
ansible.builtin.set_fact:
protection_policy_ext_id_1: "{{ result.protection_policy_ext_id }}"

- name: Create auto retention protection policy
nutanix.ncp.ntnx_protection_policies_v2:
name: "ansible-name-auto-{{random_name}}"
description: "ansible-description-auto-{{random_name}}"
replication_locations:
- "{{ replication_location_1 }}"
- "{{ replication_location_2 }}"
replication_configurations:
- source_location_label: "{{ replication_configuration_auto_1.source_location_label }}"
remote_location_label: "{{ replication_configuration_auto_1.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_auto_1.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_auto_1.schedule.recovery_point_objective_time_seconds | int }}"
retention:
auto_rollup_retention:
local:
snapshot_interval_type: "{{ replication_configuration_auto_1.schedule.retention.local.snapshot_interval_type }}"
frequency: "{{ replication_configuration_auto_1.schedule.retention.local.frequency }}"
remote:
snapshot_interval_type: "{{ replication_configuration_auto_1.schedule.retention.remote.snapshot_interval_type }}"
frequency: "{{ replication_configuration_auto_1.schedule.retention.remote.frequency }}"
start_time: "{{ replication_configuration_auto_1.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds: "{{ replication_configuration_auto_1.schedule.sync_replication_auto_suspend_timeout_seconds }}"
- source_location_label: "{{ replication_configuration_auto_2.source_location_label }}"
remote_location_label: "{{ replication_configuration_auto_2.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_auto_2.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_auto_2.schedule.recovery_point_objective_time_seconds | int }}"
retention:
auto_rollup_retention:
local:
snapshot_interval_type: "{{ replication_configuration_auto_2.schedule.retention.local.snapshot_interval_type }}"
frequency: "{{ replication_configuration_auto_2.schedule.retention.local.frequency }}"
remote:
snapshot_interval_type: "{{ replication_configuration_auto_2.schedule.retention.remote.snapshot_interval_type }}"
frequency: "{{ replication_configuration_auto_2.schedule.retention.remote.frequency }}"
start_time: "{{ replication_configuration_auto_2.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds: "{{ replication_configuration_auto_2.schedule.sync_replication_auto_suspend_timeout_seconds }}"
category_ids:
- "{{category_ext_id_2}}"
register: result

- name: Set protection policy ext id
ansible.builtin.set_fact:
protection_policy_ext_id_2: "{{ result.protection_policy_ext_id }}"

- name: Update linear retention protection policy
nutanix.ncp.ntnx_protection_policies_v2:
ext_id: "{{ protection_policy_ext_id_1 }}"
name: "ansible-name-linear-{{random_name}}_updated"
description: "ansible-description-linear-{{random_name}}_updated"
replication_locations:
- "{{ replication_location_1_updated }}"
- "{{ replication_location_2_updated }}"
replication_configurations:
- source_location_label: "{{ replication_configuration_linear_1_updated.source_location_label }}"
remote_location_label: "{{ replication_configuration_linear_1_updated.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_linear_1_updated.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_linear_1_updated.schedule.recovery_point_objective_time_seconds | int }}"
retention:
linear_retention:
local: "{{ replication_configuration_linear_1_updated.schedule.retention.local }}"
remote: "{{ replication_configuration_linear_1_updated.schedule.retention.remote }}"
start_time: "{{ replication_configuration_linear_1_updated.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds:
"{{ replication_configuration_linear_1_updated.schedule.
sync_replication_auto_suspend_timeout_seconds }}"
- source_location_label: "{{ replication_configuration_linear_2_updated.source_location_label }}"
remote_location_label: "{{ replication_configuration_linear_2_updated.remote_location_label }}"
schedule:
recovery_point_type: "{{ replication_configuration_linear_2_updated.schedule.recovery_point_type }}"
recovery_point_objective_time_seconds: "{{ replication_configuration_linear_2_updated.schedule.recovery_point_objective_time_seconds | int }}"
retention:
linear_retention:
local: "{{ replication_configuration_linear_2_updated.schedule.retention.local }}"
remote: "{{ replication_configuration_linear_2_updated.schedule.retention.remote }}"
start_time: "{{ replication_configuration_linear_2_updated.schedule.start_time }}"
sync_replication_auto_suspend_timeout_seconds:
"{{ replication_configuration_linear_2_updated.schedule.
sync_replication_auto_suspend_timeout_seconds }}"
category_ids:
- "{{category_ext_id_1}}"
register: result

- name: List all protection policies
nutanix.ncp.ntnx_protection_policies_info_v2:
register: result

- name: List all protection policies with filter
nutanix.ncp.ntnx_protection_policies_info_v2:
filter: "name eq 'ansible-name-auto-{{random_name}}_updated'"
register: result

- name: List all protection policies with limit
nutanix.ncp.ntnx_protection_policies_info_v2:
limit: 1
register: result

- name: Delete linear protection policy
nutanix.ncp.ntnx_protection_policies_v2:
ext_id: "{{ protection_policy_ext_id_1 }}"
state: absent
register: result

- name: Delete auto protection policy
nutanix.ncp.ntnx_protection_policies_v2:
ext_id: "{{ protection_policy_ext_id_2 }}"
state: absent
register: result

0 comments on commit 3f96326

Please sign in to comment.