-
Notifications
You must be signed in to change notification settings - Fork 53
ansible #50
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
ansible #50
Changes from all commits
7441d7d
cd17c13
ce0853a
b44948e
762e16e
b7aff31
259213b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||||||||||||||
### NetBackup API Code Samples for Ansible | ||||||||||||||||||
|
||||||||||||||||||
This directory contains code samples to invoke NetBackup REST APIs using ansible. | ||||||||||||||||||
|
||||||||||||||||||
#### Disclaimer | ||||||||||||||||||
|
||||||||||||||||||
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. | ||||||||||||||||||
|
||||||||||||||||||
#### Pre-requisites: | ||||||||||||||||||
|
||||||||||||||||||
- NetBackup 8.1.1 or higher | ||||||||||||||||||
- ansible 2.x | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalize proper nouns.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
#### Executing the snippets in ansible | ||||||||||||||||||
|
||||||||||||||||||
These are tasks meant to be part of a larger playbook. I use them with the following syntax | ||||||||||||||||||
|
||||||||||||||||||
tasks: | ||||||||||||||||||
-name: name of tasks | ||||||||||||||||||
include_task: tasklocation/taskname | ||||||||||||||||||
Comment on lines
+19
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mark for display as code, and make it valid YAML syntax.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
Vars for ansible are defined in a inventory file for use in plays | ||||||||||||||||||
vars created during plays are used in future ones like login.yml. | ||||||||||||||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Markdown renders this as one sentence. And passive voice makes it unclear whose responsibility it is to perform the actions described here.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
- name: login | ||
uri: | ||
url: "{{baseurl}}login" | ||
method: POST | ||
body_format: json | ||
status_code: 201 | ||
headers: | ||
content-type: application/vnd.netbackup+json;version=3.0 | ||
body: | ||
userName: "{{username}}" | ||
password: "{{password}}" | ||
validate_certs: no | ||
return_content: yes | ||
register: login | ||
|
||
- name: set facts | ||
set_fact: | ||
login_token: "{{login.json.token}}" | ||
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some plays use |
||
- name: debug token | ||
debug: | ||
msg: "{{login_token}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
--- | ||
|
||
- name: Create storage server | ||
uri: | ||
url: "{{baseurl}}storage/storage-servers" | ||
method: POST | ||
body_format: json | ||
status_code: 201, 409 | ||
headers: | ||
authorization: "{{login.json.token}}" | ||
content-type: application/vnd.netbackup+json;version=3.0 | ||
body: | ||
data: | ||
type: storageServer | ||
attributes: | ||
name: "{{mediaserver}}.{{domain}}" | ||
storageCategory: MSDP | ||
mediaServerDetails: | ||
name: "{{mediaserver}}.{{domain}}" | ||
encryptionEnabled: false | ||
msdpAttributes: | ||
storagePath: /mnt/msdp/vol0 | ||
credentials: | ||
userName: msdp | ||
password: msdp | ||
validate_certs: no | ||
return_content: yes | ||
register: stgsvr_create | ||
- name: debug stgsvr_create | ||
debug: | ||
msg: "{{stgsvr_create}}" | ||
|
||
- name: Create MSDP Disk Pool | ||
uri: | ||
url: "{{baseurl}}storage/disk-pools" | ||
method: POST | ||
body_format: json | ||
status_code: 201, 409 | ||
headers: | ||
authorization: "{{login.json.token}}" | ||
content-type: application/vnd.netbackup+json;version=3.0 | ||
body: | ||
data: | ||
type: diskPool | ||
attributes: | ||
name: "{{mediaserver}}"_dpm | ||
diskVolumes: | ||
- name: PureDiskVolume | ||
maximumIoStreams: | ||
limitIoStreams: true | ||
streamsPerVolume: 75 | ||
relationships: | ||
storageServers: | ||
data: | ||
- type: storageServer | ||
id: "PureDisk:{{mediaserver}}.{{domain}}" | ||
validate_certs: no | ||
return_content: yes | ||
register: dp_create | ||
- name: debug dp_Create | ||
debug: | ||
msg: "{{dp_create}}" | ||
|
||
- name: Create MSDP Storage Unit | ||
uri: | ||
url: "{{baseurl}}storage/storage-units" | ||
method: POST | ||
body_format: json | ||
status_code: 201 | ||
headers: | ||
authorization: "{{login.json.token}}" | ||
content-type: application/vnd.netbackup+json;version=3.0 | ||
body: | ||
data: | ||
type: storageUnit | ||
attributes: | ||
name: "{{mediaserver}}"_dpm_su | ||
useAnyAvailableMediaServer: true | ||
maxFragmentSizeMegabytes: 51200 | ||
maxConcurrentJobs: 100 | ||
onDemandOnly: true | ||
relationships: | ||
diskPool: | ||
data: | ||
type: diskPool | ||
id: "PureDisk:"{{mediaserver}}"_dpm" | ||
validate_certs: no | ||
return_content: yes | ||
register: stu_create | ||
- name: debug stu_Create | ||
debug: | ||
msg: "{{stu_create}}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
### Requirements | ||
# inputs from parent - {{login_token}}, | ||
# inputs from inventory - {{baseurl}}, {{master}}, {{vcenter}} | ||
# outputs {{slo_create}} | ||
- name: SLO Create | ||
uri: | ||
url: "{{baseurl}}servicecatalog/slos" | ||
method: POST | ||
body_format: json | ||
status_code: 201 | ||
headers: | ||
authorization: "{{login_token}}" | ||
content-type: "{{contenttype}}" | ||
body: | ||
data: | ||
type: slov3 | ||
attributes: | ||
name: "ams03_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test" | ||
description: "ansible testing protection plans" | ||
policyNamePrefix: "dc01_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test" | ||
workloadType: VMWARE | ||
schedules: | ||
- scheduleType: FULL | ||
frequencySeconds: 604800 | ||
retention: | ||
value: 30 | ||
unit: DAYS | ||
backupStorageUnit: dc01nbumed01_dpm_su | ||
backupWindows: | ||
- dayOfWeek: 6 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- scheduleType: DIFFERENTIAL_INCREMENTAL | ||
frequencySeconds: 86400 | ||
retention: | ||
value: 30 | ||
unit: DAYS | ||
backupStorageUnit: dc01nbumed01_dpm_su | ||
backupWindows: | ||
- dayOfWeek: 1 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 2 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 3 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 4 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 5 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 7 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
policyDefinition: | ||
policy: | ||
policyName: "dc1_{{item.seg}}v_{{item.type}}_fr_{{item.time}}_{{item.ret}}_ansible_test" | ||
policyType: VMware | ||
policyAttributes: | ||
active: false | ||
jobLimit: 2147483647 | ||
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" | ||
useAccelerator: true | ||
autoManagedType: 2 | ||
backupHost: MEDIA_SERVER | ||
blockIncremental: true | ||
dataClassification: | ||
disableClientSideDeduplication: false | ||
discoveryLifetime: 28800 | ||
mediaOwner: "*ANY*" | ||
priority: 0 | ||
storage: | ||
storageIsSLP: false | ||
useReplicationDirector: false | ||
volumePool: NetBackup | ||
schedules: | ||
- backupType: Full Backup | ||
backupCopies: | ||
copies: | ||
- retentionPeriod: | ||
value: 1 | ||
unit: DAYS | ||
storage: SLO_UUID_bd72e69e-c3d4-4446-8273-4646b1f5d614_Backup_Only_29d7ad56-1ab7-4876-a00f-4868433ea149 | ||
priority: -1 | ||
frequencySeconds: 604800 | ||
mediaMultiplexing: 1 | ||
retriesAllowedAfterRunDay: false | ||
scheduleName: Full | ||
scheduleType: Frequency | ||
snapshotOnly: false | ||
storageIsSLP: true | ||
startWindow: | ||
- dayOfWeek: 6 | ||
durationSeconds: 28000 | ||
startSeconds: 64800 | ||
- backupType: "Differential Incremental Backup" | ||
backupCopies: | ||
copies: | ||
- retentionPeriod: | ||
value: 1 | ||
unit: DAYS | ||
storage: SLO_UUID_bd72e69e-c3d4-4446-8273-4646b1f5d614_Backup_Only_29d7ad56-1ab7-4876-a00f-4868433ea149 | ||
priority: -1 | ||
frequencySeconds: 86400 | ||
mediaMultiplexing: 1 | ||
retriesAllowedAfterRunDay: false | ||
scheduleName: DIFF_INC | ||
scheduleType: Frequency | ||
snapshotOnly: false | ||
storageIsSLP: true | ||
startWindow: | ||
- dayOfWeek: 1 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 2 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 3 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 4 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 5 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
- dayOfWeek: 7 | ||
durationSeconds: 28800 | ||
startSeconds: 64800 | ||
validate_certs: no | ||
return_content: yes | ||
|
||
with_items: | ||
- { seg: 'e', time: '1800', type: 'wi', ret: '30' } | ||
- { seg: 'i', time: '1800', type: 'wi', ret: '30' } | ||
- { seg: 's', time: '1800', type: 'wi', ret: '30' } | ||
|
||
# validate_certs: no | ||
# return_content: yes | ||
register: slo_create | ||
- name: debug vmware_resource | ||
debug: | ||
msg: "{{slo_create}}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
- name: vmware resource limits | ||
uri: | ||
url: "{{baseurl}}config/resource-limits" | ||
method: POST | ||
body_format: json | ||
status_code: 204 | ||
headers: | ||
authorization: "{{login.json.token}}" | ||
content-type: application/vnd.netbackup+json;version=3.0 | ||
body: | ||
data: | ||
- type: resource-limits | ||
id: vmware | ||
attributes: | ||
resources: | ||
- resourceType: vCenter | ||
resourceLimit: 50 | ||
- resourceType: ESXserver | ||
resourceLimit: 2 | ||
- resourceType: Datastore | ||
resourceLimit: 2 | ||
|
||
validate_certs: no | ||
return_content: yes | ||
register: vmware_resource | ||
- name: debug vmware_resource | ||
debug: | ||
msg: "{{vmware_resource}}" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
### Requirements | ||
# inputs from parent - {{login_token}}, | ||
# inputs from inventory - {{master}}, {{vcenter}}, {{baseurl}}, {{contenttype}} | ||
# outputs {{protectionplan}}, {{pp_id}} | ||
|
||
- name: add corp folder protection plan | ||
uri: | ||
url: "{{baseurl}}asset-groups" | ||
method: post | ||
body_format: json | ||
headers: | ||
authorization: "{{login_token}}" | ||
content-type: "{{contenttype}}" | ||
body: | ||
data: | ||
attributes: | ||
displayName: "{{item.seg}}-folder-test" | ||
description: "selects all {{item.seg}} folders for all vcenters in region" | ||
oDataQueryFilter: "contains(extendedAttributes/vmFolder, '{{item.seg}}') or (contains(extendedAttributes/vmFolder, '{{item.type}}'))" | ||
vipQueryFilter: "((VMFolder Contains '{{item.seg}}') OR (VMFolder Contains '{{item.type}}')) AND ((vCenter Equal '{{vcenter}}') OR (ESXserver Equal '{{vcenter}}'))" | ||
assetType: "Virtual Machine" | ||
workloadType: VMware | ||
filterConstraint: "{{vcenter}}" | ||
type: assetGroup | ||
port: 0 | ||
validate: true | ||
status_code: 201 | ||
validate_certs: no | ||
return_content: yes | ||
with_items: | ||
- {seg: 'BU1', type: 'Image Backup' } | ||
- {seg: 'BU2', type: 'Image Backup' } | ||
- {seg: 'BU3', type: 'Image Backup' } | ||
register: protectionplan | ||
ignore_errors: true | ||
|
||
- name : debug protectionplan var | ||
debug: | ||
msg: "{{protectionplan}}" | ||
|
||
- name: Set Fact - Protection Plan ID | ||
set_fact: | ||
pp_id: "{{protectionplan.json.data.id}}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start headings at level 1 instead of level 3, please.