diff --git a/snippets/ansible/VMWare_Protection_Workflow/README.md b/snippets/ansible/VMWare_Protection_Workflow/README.md new file mode 100644 index 0000000..feb23f1 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/README.md @@ -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 + + 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. diff --git a/snippets/ansible/VMWare_Protection_Workflow/inventory/netbackup.yml b/snippets/ansible/VMWare_Protection_Workflow/inventory/netbackup.yml new file mode 100644 index 0000000..c3972b8 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/inventory/netbackup.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/nbu_default_vmware_protection.yml b/snippets/ansible/VMWare_Protection_Workflow/nbu_default_vmware_protection.yml new file mode 100644 index 0000000..434852e --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/nbu_default_vmware_protection.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/login.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/login.include.yml new file mode 100644 index 0000000..3a9d76b --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/login.include.yml @@ -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}}" diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.dedicated.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.dedicated.include.yml new file mode 100644 index 0000000..5335453 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.dedicated.include.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.include.yml new file mode 100644 index 0000000..5407abc --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.include.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.tags.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.tags.include.yml new file mode 100644 index 0000000..bbaa726 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.tags.include.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.workflow.standards.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.workflow.standards.yml new file mode 100644 index 0000000..cac2799 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmware.default.workflow.standards.yml @@ -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' } diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_include.yml new file mode 100644 index 0000000..2359670 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_include.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_tags_include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_tags_include.yml new file mode 100644 index 0000000..6c4b5c4 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_create_tags_include.yml @@ -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 diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_jobstatus.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_jobstatus.yml new file mode 100644 index 0000000..4953c11 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_assetgroup_jobstatus.yml @@ -0,0 +1,57 @@ +--- + ### Requirements + # Takes inputs to check job status + # inputs from parent - {{login_token}},{{url_parms}} + # inputs from inventory - {{master}}, {{vcenter}}, {{baseurl}}, {{contenttype}}, {{sitecode}} + # outputs {{protectionplan}}, {{assetgroup_id}} + + - name: debug uri for query results on the task creating the assetgroup + debug: + msg: + - "{{assetgroup.location}}" + + - name: Get the task status for the creation of the assetgroup + uri: + url: "{{assetgroup.location}}" + method: GET + body_format: json + status_code: 200 + headers: + authorization: "{{login_token}}" + content-type: "{{contenttype}}" + validate_certs: no + return_content: yes + register: taskstatus + until: taskstatus.json.data[0].attributes.status != "IN_PROGRESS" + retries: 6 + delay: 10 + + + - name: debug results of the task creation + debug: + msg: + - "{{taskstatus.json.data[0].attributes.status}}" + - "{{taskstatus.json.data[0].attributes.workItemResponses}}" + + + + - name: get assetgroup by query of assetgroup name + uri: + url: "{{baseurl}}asset-service/workloads/vmware/assets?filter=assetType%20eq%20%27vmGroup%27%20and%20commonAssetAttributes%2FdisplayName%20eq%20%27{{url_parms}}%27" + method: GET + body_format: json + status_code: 200 + headers: + authorization: "{{login_token}}" + content-type: "{{contenttype}}" + validate_certs: no + return_content: yes + register: assetgroup + + - name: debug assetgroup + debug: + msg: "{{assetgroup.json.data[0].id}}" + + - name: Set Fact - Asset Group ID + set_fact: + assetgroup_id: "{{assetgroup.json.data[0].id}}" diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_slo_create.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_slo_create.include.yml new file mode 100644 index 0000000..d682b25 --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_slo_create.include.yml @@ -0,0 +1,232 @@ +--- + ### Requirements + # inputs from parent - {{login_token}} + # inputs from inventory - {{baseurl}}, {{master}}, {{vcenter}}, {{sitecode}}, {{vm_slo_storage_id}}, {{vm_backup_storageunit}} + # outputs {{slo_create}}, {{slo_id}} + + - name: set time if item.time is definded -- folders + set_fact: + time: "{{item.time}}" + when: item.time is defined + + - name: set time if item.tagtime is definded -- tags + set_fact: + time: "{{item.tagtime}}" + when: item.tagtime is defined + + - name: debug time + debug: var=time + + - name: set startsec var based on time value - 1800 + set_fact: + startsec: 64800 + when: time == "1800" + - name: set startsec var based on time value - 2200 + set_fact: + startsec: 79200 + when: time == "2200" + - name: set startsec var based on time value - 0200 + set_fact: + startsec: 7200 + when: time == "0200" + - name: set startsec var based on time value - 0400 + set_fact: + startsec: 14400 + when: time == "0400" + + - name: set priority var based on prod value to Eq + set_fact: + priority: 60000 + when: item.prod == "eq" + - name: set fullprod var based on prod value to Ne + set_fact: + priority: 50000 + when: item.prod == "ne" + + - name: debug policy name use + debug: + msg: "{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}" + + + - name: SLO Create + uri: + url: "{{baseurl}}servicecatalog/slos" + method: POST + body_format: json + status_code: + - 201 + - 409 + headers: + authorization: "{{login_token}}" + content-type: "{{contenttype}}" + body: + data: + type: "slov3" + attributes: + name: "{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}" + description: "ansible defined SLO Default configurations. Changes should be made in ansible" + policyNamePrefix: "{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}" + workloadType: VMWARE + schedules: + - scheduleType: FULL + frequencySeconds: 604800 + retention: + value: "{{item.ret}}" + unit: DAYS + backupStorageUnit: "{{vm_backup_storageunit}}" + backupWindows: + - dayOfWeek: 6 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - scheduleType: DIFFERENTIAL_INCREMENTAL + frequencySeconds: 86400 + retention: + value: "{{item.ret}}" + unit: DAYS + backupStorageUnit: "{{vm_backup_storageunit}}" + backupWindows: + - dayOfWeek: 1 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 2 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 3 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 4 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 5 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 7 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + policyDefinition: + policy: + policyName: "{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}" + 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={{item.driveselect}},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: "{{priority}}" + storage: + storageIsSLP: false + useReplicationDirector: false + volumePool: NetBackup + schedules: + - backupType: Full Backup + backupCopies: + copies: + - retentionPeriod: + value: "{{item.ret}}" + unit: DAYS + storage: "{{vm_backup_storageunit}}" + priority: -1 + frequencySeconds: 604800 + mediaMultiplexing: 1 + retriesAllowedAfterRunDay: false + scheduleName: Full + scheduleType: Frequency + snapshotOnly: false + storageIsSLP: true + startWindow: + - dayOfWeek: 6 + durationSeconds: 28000 + startSeconds: "{{startsec}}" + - backupType: "Differential Incremental Backup" + backupCopies: + copies: + - retentionPeriod: + value: "{{item.ret}}" + unit: DAYS + storage: "{{vm_backup_storageunit}}" + priority: -1 + frequencySeconds: 86400 + mediaMultiplexing: 1 + retriesAllowedAfterRunDay: false + scheduleName: DIFF_INC + scheduleType: Frequency + snapshotOnly: false + storageIsSLP: true + startWindow: + - dayOfWeek: 1 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 2 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 3 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 4 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 5 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + - dayOfWeek: 7 + durationSeconds: 28800 + startSeconds: "{{startsec}}" + validate_certs: no + return_content: yes + register: slo_create + + - name: debug vmware_resource + debug: + msg: "{{slo_create.status}}" + + - name: set uri status to var + set_fact: + uristat: "{{slo_create.status}}" + + - name: debug uristat + debug: + var: uristat + + - name: get slo object if create exit with 409 + uri: + url: "{{baseurl}}servicecatalog/slos?filter=name%20eq%20%27{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}%27" + method: GET + body_format: json + status_code: + - 200 + headers: + authorization: "{{login_token}}" + content-type: "{{contenttype}}" +# queries: +# filter: name eq "{{sitecode}}_{{item.segabv}}v_{{item.ptype}}_fr_{{time}}_{{item.ret}}" + validate_certs: no + return_content: yes + register: slo_get + when: uristat == "409" + + +# - name: debug slo get +# debug: +# msg: "{{slo_get.json.data[0].id}}" +# when: slo_get is defined + +# - name: debug slo_id +# debug: +# msg: "{{slo_create.json.data.id}}" +# + - name: set slo_id if create was sucess + set_fact: + slo_id: "{{slo_create.json.data.id}}" + when: uristat == "201" + + - name: set slo_id if create failed + set_fact: + slo_id: "{{slo_get.json.data[0].id}}" + when: uristat == "409" diff --git a/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_subscribe.include.yml b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_subscribe.include.yml new file mode 100644 index 0000000..8cd198b --- /dev/null +++ b/snippets/ansible/VMWare_Protection_Workflow/tasks/vmworkflow_subscribe.include.yml @@ -0,0 +1,35 @@ +--- + + - name: debug required vars + debug: + msg: + - "slo id is {{slo_id}}" + - "assetgroup_id is {{assetgroup_id}}" + + - name: Subscribe AssetGroup to SLO + uri: + url: "{{baseurl}}servicecatalog/slos/{{slo_id}}/subscriptions" + method: POST + body_format: json + status_code: + - 201 + - 409 + headers: + authorization: "{{login_token}}" + content-type: "{{contenttype}}" + body: + data: + type: subscription + attributes: + selectionType: ASSETGROUP + selectionId: "{{assetgroup_id}}" + isCustomized: false + validate_certs: no + return_content: yes + register: subscribe_create + + + + - name: debug Subscribe create + debug: + msg: "{{subscribe_create.status:}}" diff --git a/snippets/powershell/modules/Get-Assets.ps1 b/snippets/powershell/modules/Get-Assets.ps1 new file mode 100644 index 0000000..39f38b6 --- /dev/null +++ b/snippets/powershell/modules/Get-Assets.ps1 @@ -0,0 +1,68 @@ +<# +.SYNOPSIS +Get NetBackup Jobs from master server. +.DESCRIPTION +Gets the list of jobs from the master server. +See https://Masterserver:1556/api-docs/index.html? +.PARAMETER assetType +The ability to filter vms or vmgroups +.EXAMPLE +Get-NbAssets -assetType vm or vmGroup +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbAssets +Created by : Nick Britton +#> + +function Get-NbAssets() +{ +[CmdletBinding()] +param ( + [Parameter(Mandatory=$true, + HelpMessage="AssetType needs to specifiy vm or vmGroup")] + [string]$assetType + + ) + $assetType = "vm" + # FUNCTION START + $results = @() + $uri = $basepath + $assetServiceUri + + $default_sort = "commonAssetAttributes.displayName" + + if($assetType -eq "vm"){ + $assetTypeFilter = "assetType eq 'vm'" + } + elseif($assetType -eq "vmGroup"){ + $assetTypeFilter = "assetType eq 'vmGroup'" + } + $offset = 0 + $next = $true + + while ($next){ + + $assetServiceUri = "/asset-service/workloads/vmware/assets" + $uri = $basepath + $assetServiceUri + $query_params = @{ + "filter" = "$assetTypeFilter" + "sort" = "commonAssetAttributes.displayName" + "page[offset]" = "$offset" + "page[limit]" = "100" + } + + $response = Invoke-WebRequest -Uri $uri -Method GET -Body $query_params -ContentType $nbcontent_type -Headers $nbheaders + + if ($response.StatusCode -ne 200) { throw "Unable to get VMware assets.`n" } + + $api_response = (ConvertFrom-Json -InputObject $response) + + $results += $api_response + #write-host "offset is $offset" + $offset = $offset + $api_response.meta.pagination.limit + if($api_response.meta.pagination.hasNext -eq $false){ $next = $false } + + } +$assetarray = $results.data +Return $assetarray +} \ No newline at end of file diff --git a/snippets/powershell/modules/Get-NbClientInfo.ps1 b/snippets/powershell/modules/Get-NbClientInfo.ps1 new file mode 100644 index 0000000..4fc28a0 --- /dev/null +++ b/snippets/powershell/modules/Get-NbClientInfo.ps1 @@ -0,0 +1,24 @@ +<# +.SYNOPSIS +Get client or host details from master server +.DESCRIPTION +Gets the host details for each client on the master and will return the details in an array. +See https://Masterserver:1556/api-docs/index.html?urls.primaryName=config#/Hosts/get_config_hosts for details on the api used. +.EXAMPLE +Get-NbClientInfo +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbClientInfo +Created by : Nick Britton +#> + +function Get-NbClientInfo() +{ +$uri = $basepath + "/config/hosts" +$response = Invoke-WebRequest -Uri $uri -Method GET -ContentType $nbcontent_type -Headers $nbheaders +if ($response.StatusCode -ne 200){ throw "Unable to get the client details"} +$content = (ConvertFrom-Json -InputObject $response) +$nbClientInfo = $content.hosts +Return $nbClientInfo +} diff --git a/snippets/powershell/modules/Get-NbDiscoveryStatus.ps1 b/snippets/powershell/modules/Get-NbDiscoveryStatus.ps1 new file mode 100644 index 0000000..4fc28a0 --- /dev/null +++ b/snippets/powershell/modules/Get-NbDiscoveryStatus.ps1 @@ -0,0 +1,24 @@ +<# +.SYNOPSIS +Get client or host details from master server +.DESCRIPTION +Gets the host details for each client on the master and will return the details in an array. +See https://Masterserver:1556/api-docs/index.html?urls.primaryName=config#/Hosts/get_config_hosts for details on the api used. +.EXAMPLE +Get-NbClientInfo +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbClientInfo +Created by : Nick Britton +#> + +function Get-NbClientInfo() +{ +$uri = $basepath + "/config/hosts" +$response = Invoke-WebRequest -Uri $uri -Method GET -ContentType $nbcontent_type -Headers $nbheaders +if ($response.StatusCode -ne 200){ throw "Unable to get the client details"} +$content = (ConvertFrom-Json -InputObject $response) +$nbClientInfo = $content.hosts +Return $nbClientInfo +} diff --git a/snippets/powershell/modules/Get-NbJobLog.ps1 b/snippets/powershell/modules/Get-NbJobLog.ps1 new file mode 100644 index 0000000..5ce3778 --- /dev/null +++ b/snippets/powershell/modules/Get-NbJobLog.ps1 @@ -0,0 +1,36 @@ +<# +.SYNOPSIS +Get NetBackup Job log for specified jobid from master server. +.DESCRIPTION +Gets the job log from the master server. +See https://Masterserver:1556/api-docs/index.html?urls.primaryName=admin#/Jobs/get_admin_jobs__jobId__try_logs for details on the api used. +The JobId can be found in the nbjobs function. +.PARAMETER jobid +JobId is required for the api call. +.EXAMPLE +Get-NbJobLog -jobid ###### +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbJobLog +Created by : Nick Britton +#> + +function Get-NbJobLog() +{ +[CmdletBinding()] +param ( + [Parameter(Mandatory=$true, + HelpMessage="Job id is required for api call")] + [string]$jobid + + ) + + $uri = $basepath + "/admin/jobs/$jobid/try-logs" + $response = Invoke-WebRequest -Uri $uri -Method GET -ContentType $nbcontent_type -Headers $nbheaders + + if ($response.StatusCode -ne 200){throw "Unable to get the Netbackup jobs!"} + $content = (ConvertFrom-Json -InputObject $response) +Return $content + +} diff --git a/snippets/powershell/modules/Get-NbJobs.ps1 b/snippets/powershell/modules/Get-NbJobs.ps1 new file mode 100644 index 0000000..7e6a037 --- /dev/null +++ b/snippets/powershell/modules/Get-NbJobs.ps1 @@ -0,0 +1,49 @@ +<# +.SYNOPSIS +Get NetBackup Jobs from master server. +.DESCRIPTION +Gets the list of jobs from the master server. +See https://Masterserver:1556/api-docs/index.html?urls.primaryName=admin#/Jobs/get_admin_jobs for details on the api used. +.PARAMETER filter +The odata filter to apply. See link above for details. Ex. "policyType eq '$policyType' and jobId ne parentJobId" +.PARAMETER pagelimit +Limit the number of records per page +.EXAMPLE +Get-NbJobs -filter policyType eq policyType and jobId ne parentJobId -pagelimit 99 +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbJobs +Created by : Nick Britton +#> + +function Get-NbJobs() +{ +[CmdletBinding()] +param ( + [Parameter(Mandatory=$false, + HelpMessage="Filter in odata format. Ex. policyType eq policyType and jobId ne parentJobId")] + [string]$filter, + [Parameter(Mandatory=$false, + HelpMessage="Page limit 0-99")] + [string]$pagelimit + ) +$uri = $basepath + "/admin/jobs" + +$query_params = @{ + "filter" = "$filter" # This adds a filter to only show the restore jobs + "page[limit]" = "$pagelimit" + + } + +$response = Invoke-WebRequest -Uri $uri -Method GET -Body $query_params -ContentType $nbcontent_type -Headers $nbheaders + +if ($response.StatusCode -ne 200) { throw "Unable to get the Netbackup jobs!"} + +$content = (ConvertFrom-Json -InputObject $response) + + +$jobarray = $content.data +Return $jobarray + +} diff --git a/snippets/powershell/modules/Get-NbLogin.ps1 b/snippets/powershell/modules/Get-NbLogin.ps1 new file mode 100644 index 0000000..23d34c8 --- /dev/null +++ b/snippets/powershell/modules/Get-NbLogin.ps1 @@ -0,0 +1,32 @@ +<# +.SYNOPSIS +Login to NetBackup Api. +.DESCRIPTION +Logs into the netbackup instance, via the api functions. +.EXAMPLE +Get-NbLogin +.OUTPUTS +String +Sets nbheaders var in parent script +.NOTES +FunctionName : Get-Login +Created by : Nick Britton +#> + +function Get-NbLogin() +{ +$uri = $basepath + "/login" + +$body = @{ + userName=$username + password=$password + } +$response = Invoke-WebRequest -Uri $uri -Method POST -Body (ConvertTo-Json -InputObject $body) -ContentType $nbcontent_type + +if ($response.StatusCode -ne 201) { throw "Unable to connect to the Netbackup master server!" } + +$content = (ConvertFrom-Json -InputObject $response) +$logintoken = $content.token +$script:nbheaders = @{ "Authorization" = $logintoken} +return $logintoken +} diff --git a/snippets/powershell/modules/Get-NbVMDiscoveryStatus.ps1 b/snippets/powershell/modules/Get-NbVMDiscoveryStatus.ps1 new file mode 100644 index 0000000..49359af --- /dev/null +++ b/snippets/powershell/modules/Get-NbVMDiscoveryStatus.ps1 @@ -0,0 +1,41 @@ +<# +.SYNOPSIS +Get client or host details from master server +.DESCRIPTION +Gets the host details for each client on the master and will return the details in an array. +See https://Masterserver:1556/api-docs/index.html?urls.primaryName=config#/Hosts/get_config_hosts for details on the api used. +.EXAMPLE +Get-NbClientInfo +.OUTPUTS +Array +.NOTES +FunctionName : Get-NbDiscoveryStatus +Created by : Nick Britton +#> + +function Get-NbVMDiscoveryStatus() +{ +$uri = $basepath + "/admin/discovery/workloads/vmware/status" +$query_params = @{ + "page[limit]" = "99" + + } +$response = Invoke-WebRequest -Uri $uri -Method GET -Body $query_params -ContentType $nbcontent_type -Headers $nbheaders +if ($response.StatusCode -ne 200){ throw "Unable to get the client details"} +$content = (ConvertFrom-Json -InputObject $response) +$data = $content.data + +$properties = + @{Label = "vcenter"; Expression = { $_.attributes.ServerName }}, + @{Label = "workload"; Expression = { $_.attributes.WorkloadType }}, + @{Label = "Status"; Expression = { $_.attributes.discoveryStatus }}, + @{Label = "StartTime"; Expression = { $_.attributes.discoveryStartTime }}, + @{Label = "EndTime"; Expression = { $_.attributes.discoveryFinishTime }}, + @{Label = "ModifyTime"; Expression = { $_.attributes.lastModifiedDateTime }}, + @{Label = "DiscoveryHost"; Expression = { $_.attributes.additionalAttributes.discoveryHost }}, + @{Label = "DiscoveryFreq"; Expression = { $_.attributes.additionalAttributes.discoveryFrequencySeconds }}, + @{Label = "DiscoveryDisabled"; Expression = { $_.attributes.additionalAttributes.isDiscoveryDisabled }} + + $data = $data|Select-Object -Property $properties +Return $data +} diff --git a/snippets/powershell/modules/README.md b/snippets/powershell/modules/README.md new file mode 100644 index 0000000..0c2a464 --- /dev/null +++ b/snippets/powershell/modules/README.md @@ -0,0 +1,9 @@ +To use modules we include this in all of our scripts: +This will search for all the modules and make them available. We update the drive letter depending on use case. + +$PS_Modules = Get-ChildItem c:\ -ErrorAction SilentlyContinue -filter "GTSESS*-modules" -Recurse +foreach ($module in $PS_Modules) +{ +$path = $module.FullName +get-childitem $path\*.ps1 -Recurse | % {. $_.FullName} +} diff --git a/snippets/powershell/modules/Set-NbInitalSetup.ps1 b/snippets/powershell/modules/Set-NbInitalSetup.ps1 new file mode 100644 index 0000000..4e2b489 --- /dev/null +++ b/snippets/powershell/modules/Set-NbInitalSetup.ps1 @@ -0,0 +1,51 @@ +<# +.SYNOPSIS +Setup NetBackup Env. +.DESCRIPTION +Sets up the Netbackup api enviornment for the parent script. Will set nbcontent_type that is used in other functions for other calls +.EXAMPLE +Set-NbInitialSetup +.OUTPUTS +Sets nbcontent_type Variable +.NOTES +FunctionName : Set-NbInitialSetup +Created by : Nick Britton +#> + +##################################################################### +# Initial Setup +# Note: This allows self-signed certificates and enables TLS v1.2 +##################################################################### + +function Set-NbInitialSetup() +{ + # Allow self-signed certificates + if ([System.Net.ServicePointManager]::CertificatePolicy -notlike 'TrustAllCertsPolicy') + { + Add-Type -TypeDefinition @" + using System.Net; + using System.Security.Cryptography.X509Certificates; + public class TrustAllCertsPolicy : ICertificatePolicy { + public bool CheckValidationResult( + ServicePoint srvPoint, X509Certificate certificate, + WebRequest request, int certificateProblem) { + return true; + } + } +"@ + [System.Net.ServicePointManager]::CertificatePolicy = New-Object -TypeName TrustAllCertsPolicy + + # Force TLS v1.2 + try { + if ([Net.ServicePointManager]::SecurityProtocol -notcontains 'Tls12') { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } + } + catch { + Write-Host $_.Exception.InnerException.Message + } + } + # Global Variables + $script:nbcontent_type = "application/vnd.netbackup+json;version=4.0" + +} diff --git a/snippets/powershell/modules/gtsess-nbu-modules.psm1 b/snippets/powershell/modules/gtsess-nbu-modules.psm1 new file mode 100644 index 0000000..e69de29