Site icon Ron Ekins' – Oracle Technology, DevOps and Kubernetes Blog

How to use Ansible to map a Linux device to a vVOL FlashArray Volume

Background

In my previous post I walked through how you can determine a vVOL FlashArray volume from a Linux device. In this post I will show how we can automate that process with Ansible using the same /dev/sdd Linux device and some code examples.

Ansible Linux Facts

Let’s start by using the ansible_facts.devices to identify the UUID for our Linux device.

# identify database UUID 
 - name: Determine Linux UUID {{ ldevice }} 
   set_fact:
     UUID: "{{ ansible_facts.devices[ ldevice[5:]]['links']['ids'][0][5:] }}"
ok: [z-oracle8] => {
     "ansible_facts": {
         "UUID": "36000c2929a68f7a35c718056f17b091f"
     },
     "changed": false
 }

VMware stores the UUID in a slightly different format so before we can use it we need to reformat to be VMware friendly.

- name: Find VMware UUID for {{ UUID[1:] }}
   set_fact:
     formatted_UUID: "{{ UUID[1:8]|upper + UUID[8:9] + '-' + UUID[9:13] + '-' + UUID[13:17] + '-' + UUID[17:21] + '-' + UUID[21:33] }}"
ok: [z-oracle8] => {
     "ansible_facts": {
         "formatted_UUID": "6000C292-9a68-f7a3-5c71-8056f17b091f"
     },
     "changed": false
 }

Ansible VMware Facts

We now need to gather our VMware facts using vmware_guest_disk_info, however before we can use it we will need to install it from Ansible Galaxy if we haven’t already done previously.

community.vmware

Once installed you will need to include the collection e.g.

  collections:
     - community.vmware

Using the below we can now obtain the VMware Ansible facts.

- name: Get vmware guest disk facts
   community.vmware.vmware_guest_disk_info:
     datacenter: "{{ vdatacenter }}"
     name: "{{ inventory_hostname }}"
     hostname: "{{ vhostname }}"
     username: "{{ vusername }}"
     password: "{{ vpassword }}"
     validate_certs: no
   register: vmdisk

Using our VMware friendly UUID we can now determine the backing_filename for our given backing_uuid.

- name: Look-up VMware backing_filename for {{ formatted_UUID }}
   set_fact:
     formatted_BF: "{{ 'rfc' + vm_item.value.backing_filename.split('rfc')[1:] | join }}"
   when:
     - vm_item.value.backing_uuid == formatted_UUID
   with_dict: "{{ vmdisk.guest_disk_info }}"
   loop_control:
     label: "{{ vm_item.value.backing_filename }}"
     loop_var: vm_item
ok: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk) => {
     "ansible_facts": {
         "formatted_BF": "rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk"
     },
     "ansible_loop_var": "vm_item",
     "changed": false,
     "vm_item": {
         "key": "3",
         "value": {
             "backing_datastore": "z_faprod_m20_b_datastore_VVOLS",
             "backing_disk_mode": "persistent",
             "backing_diskmode": "persistent",
             "backing_eagerlyscrub": false,
             "backing_filename": "[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk",
             "backing_thinprovisioned": true,
             "backing_type": "FlatVer2",
             "backing_uuid": "6000C292-9a68-f7a3-5c71-8056f17b091f",
             "backing_writethrough": false,
             "capacity_in_bytes": 1099511627776,
             "capacity_in_kb": 1073741824,
             "controller_bus_number": 0,
             "controller_key": 1000,
             "controller_type": "paravirtual",
             "key": 2003,
             "label": "Hard disk 4",
             "summary": "1,073,741,824 KB",
             "unit_number": 3
         }
     }
 }

Pure FlashArray Volume

The next step is to use the Pure FlashArray REST API to determine the Volume name for the VMware vVOL backing_filename using the Ansible URI module querying the vasa-integration.purestorage.com namespace with the Purity 6.0 tags=true option.

You may want to check-out Postman, I find it a great way to test my REST API’s calls before I starting writing the URI calls.

Postman Output
# Get FA vVol   
 - name: Get FA vVOL 
   uri:
     url: https://{{ array.ip }}/api/{{ array.api_version }}/volume?tags=true&namespace=vasa-integration.purestorage.com&filter=(value='*{{ formatted_BF }}')
     method: GET
     headers:
       Cookie: "{{ session.set_cookie }}"
     validate_certs: "no"
     return_content: "yes"
   register: favVol

Using the above REST API code we can see our FlashArray Volume name is vvol-z-oracle8-1a4cbf5c-vg/Data-150b9725

...
   },
     "json": [
         {
             "copyable": false,
             "key": "VMW_VVolDescriptor",
             "name": "vvol-z-oracle8-1a4cbf5c-vg/Data-150b9725",
             "namespace": "vasa-integration.purestorage.com",
             "value": "/vmfs/volumes/vvol:5773d72a7cf736a5-b363fec3c84e2222/rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk"
         }
     ],
...

Ansible Playbook Output

Below is the output from my Ansible playbook.

[oracle@z-oracle ansible-oracle]$ ansible-playbook get_fa_vVol.yaml -e ldevice=/dev/sdd
PLAY [Linux to VMware to Pure disk mapping] ***********************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:48 +0000 (0:00:00.157)       0:00:00.157 **** 
ok: [z-oracle8]

TASK [Get vmware guest disk facts] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:50 +0000 (0:00:01.254)       0:00:01.412 **** 
ok: [z-oracle8 -> localhost]

TASK [Lookup Linux device /dev/sdd] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:01.059)       0:00:02.471 **** 
included: /home/oracle/ansible-oracle/tasks/lookup_device.yaml for z-oracle8

TASK [Determine Linux UUID /dev/sdd] ****************************************************************************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.069)       0:00:02.541 **** 
ok: [z-oracle8]
 
TASK [Find VMware UUID for 6000c2929a68f7a35c718056f17b091f] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.051)       0:00:02.592 **** 
ok: [z-oracle8]

TASK [Formatted UUID] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.051)       0:00:02.644 **** 
skipping: [z-oracle8]
 
TASK [Look-up VMware backing_filename for 6000C292-9a68-f7a3-5c71-8056f17b091f] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.044)       0:00:02.688 **** 
skipping: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8-000001.vmdk) 
skipping: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_1-000001.vmdk) 
skipping: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_2-000001.vmdk) 
ok: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk)
skipping: [z-oracle8] => (item=[z_faprod_m20_b_datastore_VVOLS] rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_4-000001.vmdk) 
 
TASK [vVOL Backing Filename for /dev/sdd] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.119)       0:00:02.808 **** 
skipping: [z-oracle8]
 
 TASK [Create PURE Session] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:51 +0000 (0:00:00.047)       0:00:02.855 **** 
ok: [z-oracle8 -> localhost]
 
 TASK [Get FA vVOL] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:55 +0000 (0:00:04.198)       0:00:07.053 **** 
ok: [z-oracle8 -> localhost] 

TASK [Linux vVol FlashArray Mappings ] ***********************************************************************************************************
Wednesday 02 December 2020  14:06:58 +0000 (0:00:02.187)       0:00:09.241 **** 
ok: [z-oracle8] => {
     "msg": [
         "Linux device /dev/sdd",
         "Linux UUID is 6000C292-9a68-f7a3-5c71-8056f17b091f",
         "VMware Backing File Name rfc4122.1a4cbf5c-0363-40b1-997d-cb5fe71dfcbd/z-oracle8_3-000001.vmdk",
         "FlashArray Volume vvol-z-oracle8-1a4cbf5c-vg/Data-150b9725"
     ]
 }

Summary

In this post I have shared how a simple Ansible playbook can be used to determine a vVOL FlashArray volume from a linux device.

Next step is to upload code to my GitHub Repo.

[twitter-follow screen_name=’RonEkins’ show_count=’yes’]

Exit mobile version