Skip to content

Commit 509508e

Browse files
authored
Merge pull request #50 from ntbritton/master
ansible
2 parents f00082a + 259213b commit 509508e

6 files changed

Lines changed: 361 additions & 0 deletions

File tree

snippets/ansible/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### NetBackup API Code Samples for Ansible
2+
3+
This directory contains code samples to invoke NetBackup REST APIs using ansible.
4+
5+
#### Disclaimer
6+
7+
These scripts are only meant to be used as a reference. If you intend to use them in production, use it at your own risk.
8+
9+
#### Pre-requisites:
10+
11+
- NetBackup 8.1.1 or higher
12+
- ansible 2.x
13+
14+
15+
#### Executing the snippets in ansible
16+
17+
These are tasks meant to be part of a larger playbook. I use them with the following syntax
18+
19+
tasks:
20+
-name: name of tasks
21+
include_task: tasklocation/taskname
22+
23+
24+
Vars for ansible are defined in a inventory file for use in plays
25+
vars created during plays are used in future ones like login.yml.

snippets/ansible/login.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: login
3+
uri:
4+
url: "{{baseurl}}login"
5+
method: POST
6+
body_format: json
7+
status_code: 201
8+
headers:
9+
content-type: application/vnd.netbackup+json;version=3.0
10+
body:
11+
userName: "{{username}}"
12+
password: "{{password}}"
13+
validate_certs: no
14+
return_content: yes
15+
register: login
16+
17+
- name: set facts
18+
set_fact:
19+
login_token: "{{login.json.token}}"
20+
- name: debug token
21+
debug:
22+
msg: "{{login_token}}"

snippets/ansible/msdp_create.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
3+
- name: Create storage server
4+
uri:
5+
url: "{{baseurl}}storage/storage-servers"
6+
method: POST
7+
body_format: json
8+
status_code: 201, 409
9+
headers:
10+
authorization: "{{login.json.token}}"
11+
content-type: application/vnd.netbackup+json;version=3.0
12+
body:
13+
data:
14+
type: storageServer
15+
attributes:
16+
name: "{{mediaserver}}.{{domain}}"
17+
storageCategory: MSDP
18+
mediaServerDetails:
19+
name: "{{mediaserver}}.{{domain}}"
20+
encryptionEnabled: false
21+
msdpAttributes:
22+
storagePath: /mnt/msdp/vol0
23+
credentials:
24+
userName: msdp
25+
password: msdp
26+
validate_certs: no
27+
return_content: yes
28+
register: stgsvr_create
29+
- name: debug stgsvr_create
30+
debug:
31+
msg: "{{stgsvr_create}}"
32+
33+
- name: Create MSDP Disk Pool
34+
uri:
35+
url: "{{baseurl}}storage/disk-pools"
36+
method: POST
37+
body_format: json
38+
status_code: 201, 409
39+
headers:
40+
authorization: "{{login.json.token}}"
41+
content-type: application/vnd.netbackup+json;version=3.0
42+
body:
43+
data:
44+
type: diskPool
45+
attributes:
46+
name: "{{mediaserver}}"_dpm
47+
diskVolumes:
48+
- name: PureDiskVolume
49+
maximumIoStreams:
50+
limitIoStreams: true
51+
streamsPerVolume: 75
52+
relationships:
53+
storageServers:
54+
data:
55+
- type: storageServer
56+
id: "PureDisk:{{mediaserver}}.{{domain}}"
57+
validate_certs: no
58+
return_content: yes
59+
register: dp_create
60+
- name: debug dp_Create
61+
debug:
62+
msg: "{{dp_create}}"
63+
64+
- name: Create MSDP Storage Unit
65+
uri:
66+
url: "{{baseurl}}storage/storage-units"
67+
method: POST
68+
body_format: json
69+
status_code: 201
70+
headers:
71+
authorization: "{{login.json.token}}"
72+
content-type: application/vnd.netbackup+json;version=3.0
73+
body:
74+
data:
75+
type: storageUnit
76+
attributes:
77+
name: "{{mediaserver}}"_dpm_su
78+
useAnyAvailableMediaServer: true
79+
maxFragmentSizeMegabytes: 51200
80+
maxConcurrentJobs: 100
81+
onDemandOnly: true
82+
relationships:
83+
diskPool:
84+
data:
85+
type: diskPool
86+
id: "PureDisk:"{{mediaserver}}"_dpm"
87+
validate_certs: no
88+
return_content: yes
89+
register: stu_create
90+
- name: debug stu_Create
91+
debug:
92+
msg: "{{stu_create}}"
93+

snippets/ansible/slo_post_example

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
### Requirements
3+
# inputs from parent - {{login_token}},
4+
# inputs from inventory - {{baseurl}}, {{master}}, {{vcenter}}
5+
# outputs {{slo_create}}
6+
- name: SLO Create
7+
uri:
8+
url: "{{baseurl}}servicecatalog/slos"
9+
method: POST
10+
body_format: json
11+
status_code: 201
12+
headers:
13+
authorization: "{{login_token}}"
14+
content-type: "{{contenttype}}"
15+
body:
16+
data:
17+
type: slov3
18+
attributes:
19+
name: "ams03_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test"
20+
description: "ansible testing protection plans"
21+
policyNamePrefix: "dc01_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test"
22+
workloadType: VMWARE
23+
schedules:
24+
- scheduleType: FULL
25+
frequencySeconds: 604800
26+
retention:
27+
value: 30
28+
unit: DAYS
29+
backupStorageUnit: dc01nbumed01_dpm_su
30+
backupWindows:
31+
- dayOfWeek: 6
32+
durationSeconds: 28800
33+
startSeconds: 64800
34+
- scheduleType: DIFFERENTIAL_INCREMENTAL
35+
frequencySeconds: 86400
36+
retention:
37+
value: 30
38+
unit: DAYS
39+
backupStorageUnit: dc01nbumed01_dpm_su
40+
backupWindows:
41+
- dayOfWeek: 1
42+
durationSeconds: 28800
43+
startSeconds: 64800
44+
- dayOfWeek: 2
45+
durationSeconds: 28800
46+
startSeconds: 64800
47+
- dayOfWeek: 3
48+
durationSeconds: 28800
49+
startSeconds: 64800
50+
- dayOfWeek: 4
51+
durationSeconds: 28800
52+
startSeconds: 64800
53+
- dayOfWeek: 5
54+
durationSeconds: 28800
55+
startSeconds: 64800
56+
- dayOfWeek: 7
57+
durationSeconds: 28800
58+
startSeconds: 64800
59+
policyDefinition:
60+
policy:
61+
policyName: "dc1_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test"
62+
policyType: VMware
63+
policyAttributes:
64+
active: false
65+
jobLimit: 2147483647
66+
snapshotMethodArgs: "skipnodisk=0,post_events=1,multi_org=0,Virtual_machine_backup=2,continue_discovery=1,nameuse=4,exclude_swap=1,tags_unset=0,ignore_irvm=1,rLim=10,snapact=2,enable_quiesce_failover=1,file_system_optimization=1,drive_selection=0,disable_quiesce=0,enable_vCloud=0,trantype=nbdssl,rHz=10,rTO=0"
67+
useAccelerator: true
68+
autoManagedType: 2
69+
backupHost: MEDIA_SERVER
70+
blockIncremental: true
71+
dataClassification:
72+
disableClientSideDeduplication: false
73+
discoveryLifetime: 28800
74+
mediaOwner: "*ANY*"
75+
priority: 0
76+
storage:
77+
storageIsSLP: false
78+
useReplicationDirector: false
79+
volumePool: NetBackup
80+
schedules:
81+
- backupType: Full Backup
82+
backupCopies:
83+
copies:
84+
- retentionPeriod:
85+
value: 1
86+
unit: DAYS
87+
storage: SLO_UUID_bd72e69e-c3d4-4446-8273-4646b1f5d614_Backup_Only_29d7ad56-1ab7-4876-a00f-4868433ea149
88+
priority: -1
89+
frequencySeconds: 604800
90+
mediaMultiplexing: 1
91+
retriesAllowedAfterRunDay: false
92+
scheduleName: Full
93+
scheduleType: Frequency
94+
snapshotOnly: false
95+
storageIsSLP: true
96+
startWindow:
97+
- dayOfWeek: 6
98+
durationSeconds: 28000
99+
startSeconds: 64800
100+
- backupType: "Differential Incremental Backup"
101+
backupCopies:
102+
copies:
103+
- retentionPeriod:
104+
value: 1
105+
unit: DAYS
106+
storage: SLO_UUID_bd72e69e-c3d4-4446-8273-4646b1f5d614_Backup_Only_29d7ad56-1ab7-4876-a00f-4868433ea149
107+
priority: -1
108+
frequencySeconds: 86400
109+
mediaMultiplexing: 1
110+
retriesAllowedAfterRunDay: false
111+
scheduleName: DIFF_INC
112+
scheduleType: Frequency
113+
snapshotOnly: false
114+
storageIsSLP: true
115+
startWindow:
116+
- dayOfWeek: 1
117+
durationSeconds: 28800
118+
startSeconds: 64800
119+
- dayOfWeek: 2
120+
durationSeconds: 28800
121+
startSeconds: 64800
122+
- dayOfWeek: 3
123+
durationSeconds: 28800
124+
startSeconds: 64800
125+
- dayOfWeek: 4
126+
durationSeconds: 28800
127+
startSeconds: 64800
128+
- dayOfWeek: 5
129+
durationSeconds: 28800
130+
startSeconds: 64800
131+
- dayOfWeek: 7
132+
durationSeconds: 28800
133+
startSeconds: 64800
134+
validate_certs: no
135+
return_content: yes
136+
137+
with_items:
138+
- { seg: 'e', time: '1800', type: 'wi', ret: '30' }
139+
- { seg: 'i', time: '1800', type: 'wi', ret: '30' }
140+
- { seg: 's', time: '1800', type: 'wi', ret: '30' }
141+
142+
# validate_certs: no
143+
# return_content: yes
144+
register: slo_create
145+
- name: debug vmware_resource
146+
debug:
147+
msg: "{{slo_create}}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: vmware resource limits
3+
uri:
4+
url: "{{baseurl}}config/resource-limits"
5+
method: POST
6+
body_format: json
7+
status_code: 204
8+
headers:
9+
authorization: "{{login.json.token}}"
10+
content-type: application/vnd.netbackup+json;version=3.0
11+
body:
12+
data:
13+
- type: resource-limits
14+
id: vmware
15+
attributes:
16+
resources:
17+
- resourceType: vCenter
18+
resourceLimit: 50
19+
- resourceType: ESXserver
20+
resourceLimit: 2
21+
- resourceType: Datastore
22+
resourceLimit: 2
23+
24+
validate_certs: no
25+
return_content: yes
26+
register: vmware_resource
27+
- name: debug vmware_resource
28+
debug:
29+
msg: "{{vmware_resource}}"
30+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
### Requirements
3+
# inputs from parent - {{login_token}},
4+
# inputs from inventory - {{master}}, {{vcenter}}, {{baseurl}}, {{contenttype}}
5+
# outputs {{protectionplan}}, {{pp_id}}
6+
7+
- name: add corp folder protection plan
8+
uri:
9+
url: "{{baseurl}}asset-groups"
10+
method: post
11+
body_format: json
12+
headers:
13+
authorization: "{{login_token}}"
14+
content-type: "{{contenttype}}"
15+
body:
16+
data:
17+
attributes:
18+
displayName: "{{item.seg}}-folder-test"
19+
description: "selects all {{item.seg}} folders for all vcenters in region"
20+
oDataQueryFilter: "contains(extendedAttributes/vmFolder, '{{item.seg}}') or (contains(extendedAttributes/vmFolder, '{{item.type}}'))"
21+
vipQueryFilter: "((VMFolder Contains '{{item.seg}}') OR (VMFolder Contains '{{item.type}}')) AND ((vCenter Equal '{{vcenter}}') OR (ESXserver Equal '{{vcenter}}'))"
22+
assetType: "Virtual Machine"
23+
workloadType: VMware
24+
filterConstraint: "{{vcenter}}"
25+
type: assetGroup
26+
port: 0
27+
validate: true
28+
status_code: 201
29+
validate_certs: no
30+
return_content: yes
31+
with_items:
32+
- {seg: 'BU1', type: 'Image Backup' }
33+
- {seg: 'BU2', type: 'Image Backup' }
34+
- {seg: 'BU3', type: 'Image Backup' }
35+
register: protectionplan
36+
ignore_errors: true
37+
38+
- name : debug protectionplan var
39+
debug:
40+
msg: "{{protectionplan}}"
41+
42+
- name: Set Fact - Protection Plan ID
43+
set_fact:
44+
pp_id: "{{protectionplan.json.data.id}}"

0 commit comments

Comments
 (0)