Skip to content

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

Merged
merged 7 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions snippets/ansible/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### NetBackup API Code Samples for Ansible
Copy link
Collaborator

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.

Suggested change
### NetBackup API Code Samples for Ansible
# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize proper nouns.

Suggested change
- ansible 2.x
- Ansible 2.x



#### 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
tasks:
-name: name of tasks
include_task: tasklocation/taskname
```yaml
tasks:
- name: name of tasks
include_task: tasklocation/taskname
\```



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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
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.
Define variables for Ansible in an inventory file for use in plays.
Variables registered during plays like login.yaml are used in subsequent plays.

22 changes: 22 additions & 0 deletions snippets/ansible/login.yml
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some plays use login_token, and others use login.json.token directly. What's the difference?

- name: debug token
debug:
msg: "{{login_token}}"
93 changes: 93 additions & 0 deletions snippets/ansible/msdp_create.yml
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}}"

147 changes: 147 additions & 0 deletions snippets/ansible/slo_post_example
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}}"
30 changes: 30 additions & 0 deletions snippets/ansible/vmware_resourcelimits.yml
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}}"

44 changes: 44 additions & 0 deletions vmware_asset_group_add_FolderFilter
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}}"