-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apimon playbook for cbr created playbook for cbr Reviewed-by: Vladimir Hasko <[email protected]> Reviewed-by: jmiskani
- Loading branch information
Showing
1 changed file
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
--- | ||
|
||
# Scenario to test CBR ECS server backup | ||
# A VPC is created and VM is being started in different AZs | ||
|
||
- name: Scenario 47 - CBR server backup | ||
hosts: localhost | ||
vars: | ||
prefix: scenario47- | ||
|
||
tasks: | ||
- set_fact: | ||
prefix: "{{ (prefix + ( lookup('env', 'TASK_EXECUTOR_JOB_ID') | default(99999999 | random | to_uuid | hash('md5'), true) ) ) }}" | ||
|
||
- set_fact: | ||
test_server_fqdn: "{{ (prefix + '.host') }}" | ||
test_security_group_name: "{{ (prefix + '-sg') }}" | ||
test_keypair_name: "{{ (prefix + '-kp') }}" | ||
test_network_name: "{{ ( prefix + '-net') }}" | ||
test_vault_name: "{{ ( prefix + '-vault' ) }}" | ||
test_server_name: "{{ (prefix + '-test_server_apimon') }}" | ||
test_policy_name: "{{ (prefix + '-test_policy_apimon') }}" | ||
|
||
- name: Query specific flavor | ||
openstack.cloud.compute_flavor_info: | ||
register: flavor_result | ||
|
||
- name: Query OS image | ||
openstack.cloud.image_info: | ||
register: images | ||
|
||
# Set CentOS latest | ||
- set_fact: | ||
test_image: "{{ images.images | selectattr( 'name', 'search', 'CentOS') | map(attribute='name') | first }}" | ||
|
||
# Set ECS flavor | ||
- set_fact: | ||
test_flavor: "{{ flavor_result.flavors | sort(attribute='ram') | map(attribute='name') | first }}" | ||
|
||
- block: | ||
|
||
# Prepare infrastructure and ECS server | ||
- name: Create KeyPair | ||
include_role: | ||
name: opentelekomcloud.keypair | ||
vars: | ||
keypair_name: "{{ test_keypair_name }}" | ||
state: present | ||
|
||
- name: Create VPC | ||
include_role: | ||
name: vpc | ||
vars: | ||
network_name: "{{ test_network_name }}" | ||
|
||
- name: Create Security Group | ||
openstack.cloud.security_group: | ||
name: "{{ test_security_group_name }}" | ||
description: "dummy" | ||
|
||
- name: Create Security Group Rule | ||
openstack.cloud.security_group_rule: | ||
security_group: "{{ test_security_group_name }}" | ||
protocol: tcp | ||
port_range_min: 22 | ||
port_range_max: 22 | ||
remote_ip_prefix: 0.0.0.0/0 | ||
|
||
- name: Create ECS Server in default AZ | ||
openstack.cloud.server: | ||
auto_ip: false | ||
name: "{{ test_server_name }}" | ||
image: "{{ test_image }}" | ||
flavor: "{{ test_flavor }}" | ||
key_name: "{{ test_keypair_name }}" | ||
network: "{{ test_network_name }}" | ||
register: server | ||
|
||
- name: Get ECS server ID | ||
set_fact: | ||
server_id: "{{ server.server.id }}" | ||
|
||
# Create CBR backup policy create / update | ||
- name: Create CBR Backup Policy | ||
opentelekomcloud.cloud.cbr_policy: | ||
name: "{{ test_policy_name }}" | ||
count_day_backups: 0 | ||
count_month_backups: 0 | ||
retention_duration_days: 5 | ||
count_year_backups: 0 | ||
timezone: "UTC+08:00" | ||
pattern: | ||
- "FREQ=WEEKLY;BYHOUR=14;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMINUTE=00" | ||
|
||
- name: Update CBR backup policy | ||
opentelekomcloud.cloud.cbr_policy: | ||
name: "{{ test_policy_name }}" | ||
count_day_backups: 5 | ||
pattern: | ||
- "FREQ=WEEKLY;BYHOUR=14;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMINUTE=00" | ||
is_enabled: False | ||
|
||
# CBR create vault create backup and restore ECS server | ||
- name: Create CBR server Backup Vault | ||
opentelekomcloud.cloud.cbr_vault: | ||
name: "{{ test_vault_name }}" | ||
auto_bind: false | ||
auto_expand: false | ||
policy: "{{ test_policy_name }}" | ||
billing: | ||
consistent_level: "crash_consistent" | ||
object_type: "server" | ||
protect_type: "backup" | ||
size: 40 | ||
register: vault | ||
|
||
- name: Associate resouces to CBR vault | ||
opentelekomcloud.cloud.cbr_vault: | ||
name: "{{ test_vault_name }}" | ||
resources: | ||
- id: "{{ server_id }}" | ||
type: "OS::Nova::Server" | ||
action: "associate_resources" | ||
register: vault | ||
|
||
- name: Create CBR restore point | ||
opentelekomcloud.cloud.cbr_restore_point: | ||
vault: "{{ test_vault_name }}" | ||
wait: false | ||
ignore_errors: true | ||
|
||
- name: Query backups for CBR vault | ||
opentelekomcloud.cloud.cbr_backup_info: | ||
vault: "{{ test_vault_name }}" | ||
register: backups | ||
until: backups.backups[0].status == "available" | ||
retries: 20 | ||
delay: 30 | ||
ignore_errors: false | ||
|
||
- name: Get CBR backup ID | ||
set_fact: | ||
backup_id: "{{ backups.backups.0.id }}" | ||
|
||
- name: Restore ECS server from CBR backup | ||
opentelekomcloud.cloud.cbr_backup: | ||
name: "{{ backup_id }}" | ||
server_id: "{{ server_id }}" | ||
power_on: true | ||
|
||
- name: Query backups for CBR vault | ||
opentelekomcloud.cloud.cbr_backup_info: | ||
vault: "{{ test_vault_name }}" | ||
register: backups | ||
until: backups.backups[0].status == "available" | ||
retries: 20 | ||
delay: 30 | ||
|
||
always: | ||
# Clean created resourcesd | ||
- block: | ||
|
||
- name: Delete ECS server | ||
openstack.cloud.server: | ||
state: absent | ||
name: "{{ server_id }}" | ||
|
||
- name: Delete CBR server Backup Vault | ||
opentelekomcloud.cloud.cbr_vault: | ||
name: "{{ test_vault_name }}" | ||
state: absent | ||
register: vault | ||
|
||
- name: Delete CBR backup policy | ||
opentelekomcloud.cloud.cbr_policy: | ||
name: "{{ test_policy_name }}" | ||
state: absent | ||
|
||
- name: Delete Security Group | ||
openstack.cloud.security_group: | ||
name: "{{ test_security_group_name }}" | ||
state: absent | ||
|
||
- name: Delete VPC | ||
include_role: | ||
name: vpc | ||
vars: | ||
state: absent | ||
network_name: "{{ test_network_name }}" | ||
|
||
- name: Delete KeyPair | ||
include_role: | ||
name: keypair | ||
vars: | ||
keypair_name: "{{ test_keypair_name }}" | ||
state: absent | ||
force_delete_key: true | ||
|
||
ignore_errors: true |