Skip to content

Add ansible vmware end to end workflows #85

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions snippets/ansible/VMWare_Protection_Workflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#### Executing the snippets in ansible

This is an end to end workflow. Assuming an inventory files holds vcenter info and a task file holds the specifics for the policy templates

inventory:
-- Holds inventory info


tasks:
-name: name of tasks
include_task: tasklocation/taskname
Comment on lines +5 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this meant to represent YAML? Please use code formatting. Each block is currently rendered as a single line, which probably isn't what you intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its there for an upstream ps module that imports all the modules in down stream folders such as this one.


Tasks are calling tasks to create a workflow for tags and folder support design.


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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
all:
hosts:

vars:
baseurl: https://{{master}}:1556/netbackup/
username: user
password: pass
contenttype: application/vnd.netbackup+json;version=4.0
ldapcon: domain.com

site01:
hosts:
site01nbumst01.svc.domain.com:
vars:
master: site01nbumst01.svc.domain.com
vcenters:
- site01vircen01.domain.com
sitecode: site01
sitetag: site01
datacenter: dc1
vm_backup_storageunit: site01nbumed01_dpm_su


site02:
hosts:
site02nbucormst01.svc.domain.com:
vars:
master: site02nbucormst01.svc.domain.com
vcenters:
- site02cvircenprod01.domain.com
sitecode: site02
sitetag: site02
datacenter: site02
username: user
password: password
vm_backup_storageunit: site02acw00016_dpm_su
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
### Requirements
# inputs from inventory- {{contenttype}}, {{baseurl}}, {{username}}, {{password}}
# Notes -- Base script that calls everything else.
- hosts: all
gather_facts: false
connection: local

tasks:

- name: Login - Include task
include_tasks: tasks/login.include.yml

- name: Include vmware workflow for Folder Setups
include_tasks: tasks/vmware.default.workflow.standards.yml
with_items: "{{vcenters}}"
loop_control:
loop_var: item_vcenter
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
### Requirements
# inputs from inventory- {{contenttype}}, {{baseurl}}
# inputs from parent - none
# outputs Login_token
- name: login
uri:
url: "{{baseurl}}login"
method: POST
body_format: json
status_code: 201
timeout: 300
headers:
content-type: "{{contenttype}}"
body:
userName: "{{username}}"
password: "{{password}}"
validate_certs: no
return_content: yes
register: login

- name: set facts
set_fact:
login_token: "{{login.json.token}}"
- name: debug token
debug:
msg: "{{login_token}}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
## For dedicated enviornments such as dedicated segment protection
- name: AssetGroup Post Folder Defaults - Include task
include_tasks: tasks/vmworkflow_assetgroup_create_include.yml

- name: debug asset group id var from include task
debug:
msg: "{{assetgroup_id}}"
when: assetgroup_id is defined

- name: SLO Post Folder Default Protection Plan
include_tasks: tasks/vmworkflow_slo_create.include.yml
when: assetgroup_id is defined

- name: AssetGroup Subscribe to SLO Post
include_tasks: tasks/vmworkflow_subscribe.include.yml
when: assetgroup_id is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# This is looped for each policy set of variables for the current vcenter outter loop

- name: AssetGroup Post Folder Defaults - Include task
include_tasks: tasks/vmworkflow_assetgroup_create_include.yml

- name: debug asset group id var from include task
debug:
msg: "{{assetgroup_id}}"
when: assetgroup_id is defined


- name: SLO Post Folder Default Protection Plan
include_tasks: tasks/vmworkflow_slo_create.include.yml
when: assetgroup_id is defined

- name: debug SLO id var from include task
debug:
var: slo_id
when: assetgroup_id is defined

- name: AssetGroup Subscribe to SLO Post
include_tasks: tasks/vmworkflow_subscribe.include.yml
when: assetgroup_id is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

- name: AssetGroup Post tag Defaults - Include task
include_tasks: tasks/vmworkflow_assetgroup_create_tags_include.yml

- name: debug asset group id var from include task
debug:
msg: "{{assetgroup_id}}"
when: assetgroup_id is defined

- name: SLO Post Folder Default Protection Plan
include_tasks: tasks/vmworkflow_slo_create.include.yml
when: assetgroup_id is defined

- name: debug SLO id var from include task
debug:
msg: "{{slo_id}}"
when: assetgroup_id is defined

- name: AssetGroup Subscribe to SLO Post
include_tasks: tasks/vmworkflow_subscribe.include.yml
when: assetgroup_id is defined
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
#No inputs
#Sets policies template vars, and is looped for each vcenter from previous.
#segname = segment name, segabv = segment abriviation, vmfolder = folder search string, pi = policy type such as image or image for DBs
#driveselect = parm for drive selection, ret = retention for policy, time = start time, prod = is it prod or not

- name: Include vmware workflow for Folder Setups
include_tasks: tasks/vmware.default.include.yml
with_items:
- {segname: 'BU1', segabv: '1', vmfolder: 'Bu1', btype: '\Image Backup', ptype: 'wi', driveselect: '0', ret: '30', time: '1800', prod: 'eq' }
- {segname: 'BU2', segabv: '2', vmfolder: 'Bu2', btype: '\Image Backup', ptype: 'wi', driveselect: '0', ret: '30', time: '1800', prod: 'eq' }
- {segname: 'BU1', segabv: '1', vmfolder: 'Bu1', btype: 'Image with DB Backup', ptype: 'wd', driveselect: '2', ret: '30', time: '1800', prod: 'eq' }
- {segname: 'BU2', segabv: '2', vmfolder: 'Bu2', btype: 'Image with DB Backup', ptype: 'wd', driveselect: '2', ret: '30', time: '1800', prod: 'eq' }



- name: Include vmware workflow for Tag Setups
include_tasks: tasks/vmware.default.tags.include.yml
with_items:
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '1800', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '2200', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '0200', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '0400', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '1800', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '2200', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '0200', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'pi', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '0400', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '1800', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '2200', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '0200', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '0400', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '1800', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '2200', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '0200', prod: 'eq' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'pd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '0400', prod: 'eq' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '1800', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '2200', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '0200', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU1', tagtime: '0400', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '1800', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '2200', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '0200', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image Backup', ptype: 'ni', driveselect: '0', ret: '30', tagtype: 'Image Only', tagbg: 'BU2', tagtime: '0400', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '1800', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '2200', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '0200', prod: 'ne' }
- {segname: 'BU1', segabv: '1', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU1', tagtime: '0400', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '1800', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '2200', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '0200', prod: 'ne' }
- {segname: 'BU2', segabv: '2', btype: 'Image with DB Backup', ptype: 'nd', driveselect: '2', ret: '30', tagtype: 'DB Backup', tagbg: 'BU2', tagtime: '0400', prod: 'ne' }
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
### Requirements
# Requires a set of esxi hosts in a group var
# inputs from parent - {{login_token}},
# inputs from inventory - {{master}}, {{vcenter}}, {{baseurl}}, {{contenttype}}, {{sitecode}}
# outputs {{protectionplan}}, {{assetgroup_id}}

- name: set fact for assetgroupname
set_fact:
AssetGroupName: "{{sitecode}}-{{item.segname}}-{{item.btype}}-{{item_vcenter}}-folders"

- name: set fact for urlencode
set_fact:
url_parms: "{{ AssetGroupName | urlencode }}"

- name: adds asset-group for item.segname
uri:
url: "{{baseurl}}asset-service/queries"
method: POST
body_format: json
headers:
authorization: "{{login_token}}"
content-type: "{{contenttype}}"
body:
data:
type: query
attributes:
queryName: create-or-update-assets
workloads:
- vmware
parameters:
objectList:
- correlationId: '1'
type: vmwareGroupAsset
assetGroup:
commonAssetAttributes:
detection:
detectionMethod: MANUAL
displayName: "{{AssetGroupName}}"
protectionCapabilities:
isProtectable: 'YES'
isRecoverable: 'NO'
assetType: vmGroup
description: "selects all {{item.vmfolder}} folders for {{item_vcenter}} created by ansible do NOT update."
filterConstraint: "{{item_vcenter}}"
oDataQueryFilter: contains(vmFolder, '{{item.vmfolder}}') and endswith(vmFolder, '{{item.btype}}') and contains(datacenter, '{{datacenter}}')
status_code:
- 201
- 409
validate_certs: no
return_content: yes
register: assetgroup

- name: AssetGroup Post Folder Defaults - Include task
include_tasks: tasks/vmworkflow_assetgroup_jobstatus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
### Requirements
# inputs from parent - {{login_token}},
# inputs from inventory - {{master}}, {{vcenter}}, {{baseurl}}, {{contenttype}}, {{sitecode}}
# outputs {{protectionplan}}, {{assetgroup_id}}

- name: set fullprod var based on prod value to Equal
set_fact:
prodfull: Equal
prodname: Prod
when: item.prod == "eq"
- name: set fullprod var based on prod value to NotEqual
set_fact:
prodfull: NotEqual
prodname: NonProd
when: item.prod == "ne"

- name: set fact for assetgroupname
set_fact:
AssetGroupName: "{{sitecode}}-{{item.segname}}-{{item.btype}}-{{item.tagtime}}-{{prodname}}-{{item_vcenter}}-tags"

- name: set fact for urlencode
set_fact:
url_parms: "{{ AssetGroupName | urlencode }}"


- name: adds asset-group for item.segname
uri:
url: "{{baseurl}}asset-service/queries"
method: POST
body_format: json
headers:
authorization: "{{login_token}}"
content-type: "{{contenttype}}"
body:
data:
type: query
attributes:
queryName: create-or-update-assets
workloads:
- vmware
parameters:
objectList:
- correlationId: '1'
type: vmwareGroupAsset
assetGroup:
commonAssetAttributes:
detection:
detectionMethod: MANUAL
displayName: "{{AssetGroupName}}"
protectionCapabilities:
isProtectable: 'YES'
isRecoverable: 'NO'
assetType: vmGroup
description: "selects all {{item.segname}} for {{item_vcenter}} with tags {{item.tagtime}}, {{item.tagtype}}, {{item.tagbg}}, {{prodname}} created by ansible, do NOT update."
filterConstraint: "{{item_vcenter}}"
oDataQueryFilter: tolower(tag/tagName) eq tolower('{{sitetag}}') and tolower(tag/tagName) eq tolower('{{item.tagtime}}') and tolower(tag/tagName) eq tolower('{{item.tagtype}}') and tolower(tag/tagName) eq tolower('{{item.tagbg}}') and tolower(tag/tagName) {{item.prod}} tolower('Production')
status_code:
- 201
- 409
validate_certs: no
return_content: yes
register: assetgroup

- name: AssetGroup Post Folder Defaults - Include task
include_tasks: tasks/vmworkflow_assetgroup_jobstatus.yml
Loading