Last active
November 26, 2020 17:23
-
-
Save robinsg/47fd986bc8124fc9782fc71ff9e0eeec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Create a flashcopy consistency group and mappings for all volumes mapped to a host | |
collections: | |
- ibm.spectrum_virtualize | |
gather_facts: no | |
connection: local | |
hosts: localhost | |
vars: | |
- clustername: ip_address_or_host_name | |
- username: user_name_on_storage | |
- password: your_password | |
tasks: | |
- name: Fail if a host is not defined and the ansible-playbook command | |
fails: | |
mag: | |
- 'No host specified. On the ansible-playbook command use "--extra-vars host=hostname"' | |
when: host is not defined | |
- block: | |
- name: Get a list of volume mappings for the host | |
ibm_svcinfo_command: | |
command: "svcinfo lshostvdiskmap {{ host }}" | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
register: mappings | |
- name: Get volume information for each volume mapped to the host | |
ibm_svcinfo_command: | |
command: "svcinfo lsvdisk {{ item.vdisk_name }} " | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
register: volumes | |
loop: "{{ mappings.stdout }}" | |
- name: Create a flashcopy consistency group | |
ibm_svc_fcconsistgrp: | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
name: "CG_{{ host | upper }}" | |
state: present | |
- name: Create snapshot target volumes | |
ibm_svc_vdisk: | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
name: "snap_{{ (item['stdout'] | from_json)[0].name }}" | |
state: present | |
mdiskgrp: "{{ (item['stdout'] | from_json)[0].mdisk_grp_name }}" | |
size: "{{ (item['stdout'] | from_json)[0].capacity.split('.')[0] }}" | |
unit: "{{ (item['stdout'] | from_json)[0].capacity[-2:] | lower }}" | |
rsize: "20%" | |
autoexpand: true | |
loop: "{{ volumes.results }}" | |
- name: Add flashcopy mapping to consistency group | |
ibm_svc_volume_snapshot: | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
name: "map_{{ (item['stdout'] | from_json)[0].name }}" | |
state: present | |
volume: "{{ (item['stdout'] | from_json)[0].name }}" | |
snapshot: "snap_{{ (item['stdout'] | from_json)[0].name }}" | |
consistgrp: "CG_{{ host | upper }}" | |
loop: "{{ volumes.results }}" | |
- name: Start the flashcopy consistency group | |
ibm_svc_fcconsistgrp: | |
clustername: "{{ clustername }}" | |
username: "{{ username }}" | |
password: "{{ password }}" | |
name: "CG_{{ host | upper }}" | |
state: start | |
prep: true | |
when: host is defined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment