Managing your Spectrum Virtualize with Ansible — Part 1

Article is written to help you manage your IBM Spectrum Virtualize using Ansible.

Ole Kristian Myklebust
Possimpible
7 min readApr 28, 2020

--

IBM have started creating a series of Ansible modules and plugins for interacting with the IBM Spectrum Virtualize family. These products include the IBM SAN Volume Controller, IBM FlashSystem family members built with IBM Spectrum Virtualize (FlashSystem), IBM Storwize family, and IBM Spectrum Virtualize for Public Cloud. For more information regarding these products see the IBM Knowledge Center .

For more information about the IBM Virtualize Ansible Collection :
GitHub-ibm.spectrum_virtualize
Ansible Galaxy.ibm.spectrum_virtualize

Ansible information

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy. Avoid writing scripts or custom code to deploy and update your applications — automate in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com

  • Ansible Playbooks
    It uses YAML in form of ansible-playbook. Playbook is a file where automation is defined through tasks. A task is a single step to be performed like installing a package.
  • Ansible Roles
    Roles are ways of automatically loading certain vars_files, tasks, and handlers based on a known file structure. Grouping content by roles also allows easy sharing of roles with other users.
    Roles can be dropped into Ansible PlayBooks and immediately put to work.
  • Ansible Galaxy
    Galaxy is a hub for finding and sharing Ansible content.
  • More Information about Ansible
    There is plenty of information about Ansible on Medium:
    Check out this article:

1. Prerequisite

(Something that must be gained in order to gain something else)

To be able to start using Ansible against Spectrum Virtualize you need.

  • Ansible installed on controller. (See point 2)
  • Ansible Galaxy Collection: ibm.spectrum_virtualize (See point 3.)
  • Network access to Spectrum Virtualize Managment IP.
  • A user with correct permission to create or delete object on Virtualize.
  • Spectrum Virtualize storage system must be at Version 8.1.3 or higher.

2. Install Ansible on your computer/control node. 🖥

  • To install Ansible on your control node, this could be a host, docker or your local computer, there are many guides to install Ansible out there so just google Ansible install and your OS.
  • For CentOs/Red Hat Enterprise Linux:
    You can use yum installer. $ sudo yum install ansible
    Or PiP
  • Mac:
    The preferred way to install Ansible on a Mac is via pip
    or use Brew if you have that installed.

3. Download Ansible Galaxy Collection ☁️

To install the IBM Spectrum Virtualize collection hosted in Galaxy:

ansible-galaxy collection install ibm.spectrum_virtualize

To upgrade to the latest version of the IBM Spectrum Virtualize collection:

ansible-galaxy collection install ibm.spectrum_virtualize --force

Spectrum Virtualize Ansible Modules that are available (April 2020)

ibm_svc_info — Collects information on the IBM Spectrum Virtualize system
ibm_svc_host — Host management for IBM Spectrum Virtualize
ibm_svc_mdisk — MDisk managment for IBM Spectrum Virtualize
ibm_svc_mdiskgrp — Pool management for IBM Spectrum Virtualize
ibm_svc_vdisk — Volume management for IBM Spectrum Virtualize
ibm_svc_vol_map — Volume mapping management for IBM Spectrum Virtualize

4. Ansible Playbooks 📝

After downloading the Ansible role, we need to create an Ansible playbook.

PS: If you are familary with Ansible, you can start using the playbook examples in https://github.com/olemyk/ansible-virtualize-playbooks

To use a module from the IBM Spectrum Virtualize collection, reference the full namespace, collection name, and module name that you want to use:

As mentions earlier the follwing modules are available for the moment.

  • ibm_svc_info, ibm_svc_host, ibm_svc_mdisk, ibm_svc_mdiskgrp, ibm_svc_vdisk , ibm_svc_vol_map

Let’s make a simple playbook to create an FC Host.

The best is to create a playbook with an editor that supports yaml.
- IntelliJ IDEA, Atom IDE, SubLime, notepad++
Or just use $ vi spectrum_virtualize_playbook.yml

Paste in one of the playbook examples below and change the parameters for your environment. You must at least change the parameters in vars, and check the parameters in the module ibm_svc_host.

See list below for what the options is and description.

PS: You can also use the ansible-doc command for some examples:
$ ansible-doc ibm.spectrum_virtualize.ibm_svc_vdisk

Options that is common for all modules:

Option for host:

Options for volumes:

Testing code in production.

Remember:

When you run playbooks you create and remove objects!

5. Run the playbook 🏃

To run the Ansible playbooks use the command: ansible-playbook

$ ansible-playbook spectrum_virtualize_playbook.yml

$ ansible-playbook spectrum_virtualize_playbook.ymlPLAY [Using the IBM Spectrum Virtualize collection to create an FC host] ********************************************************************TASK [Define a new FC host] ********************************************************************
changed: [localhost]
PLAY RECAP ****************************************************************************************************************************************
localhost : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

When the playbook have completed, the recap outputs what task have run.
If there is failed task, look into the play to see detailed of why it failed.

In our example the run completed with: ok=1 changed=1
To see more details. look into the logfile.

$ tail /tmp/playbook.debug
(If you haven’t changed log path)

2020–04–24T13:47:41.662 INFO 4785323456 ibm_svc_host.py:host_create():291 create host result message ‘Host, id [16], successfully created’

For verbose output you can run the ansible-playbook command with the option: -v

$ ansible-playbook spectrum_virtualize_playbook.yml -vTASK [Define a new FC host] ********************************************************************
changed: [localhost] => {"changed": true, "msg": "host ansible-host-2 has been created."}

Output will show in my case: host “ansible-host-2” has been created.

Check the Spectrum Virtualize GUI if the host is created.

To remove the host, change the option: state: to “absent

ansible-playbook spectrum_virtualize_playbook.yml -vTASK [delete FC host] *******************************************************************
changed: [localhost] => {“changed”: true, “msg”: “host [ansible-host-2] has been deleted.”}

6. Let’s run more task in same play.

  • This example will:
    Create host
    Create volume
    Map the volume to host
  • Change the option for your environment. the list of options for each module here: See list of module options here:

$ ansible-doc ibm.spectrum_virtualize.ibm_svc_vdisk

$ ansible-playbook spectrum_virtualize_playbook.yml -vPLAY [Using the IBM Spectrum Virtualize collection to create an FC host] ***********************************************TASK [Define a new FC host] *******************************************************************
changed: [localhost] => {"changed": true, "msg": "host ansible-host-1 has been created."}
TASK [Create volume] *******************************************************************
changed: [localhost] => {"changed": true, "msg": "vdisk ansible-vdisk-1 has been created."}
TASK [Map volume to host] *******************************************************************
changed: [localhost] => {"changed": true, "msg": "vdiskhostmap ansible-vdisk-1 ansible-host-1 has been created."}
PLAY RECAP *******************************************************************
localhost : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

3 Task’s is run and 3 is changed, that means that the play completed all tasks and they did changes on objects.

  • If we check the Spectrum Virtualize GUI, we will find the host and the volume is mapped to the host.

6. Let’s add more variables and play with ansible functions.

Ansible can pickup variables from several places.

In this playbook we are making our own default variables and giving default value if it’s not defined. And we are creating several hosts, volumes with the loop function.

If we use the loop function we can run the task several time with different variables. Example below is creating 2 hosts, creates 2 volumes with different volume size and mdisk pool.

You can also use “loop” function with var_files: to use when creating volume.

host_volumes_to_create.yml---
### Host to Create or Remove
hosts:
- { hostname: 'ansible-host1', fcwwpn: '10000000C9609C78' }
- { hostname: 'ansible-host2', fcwwpn: '10000000C9609C74:' }
## Volumes to Create or Remove
volumes:
- { vdiskname: 'ansible-host1-vdisk1', mdiskgrp: 'FS840-2' }
- { vdiskname: 'ansible-host2-vdisk1', vdisksize: '30' }
## Volumes mapping to Create or Remove
volume_mapping:
- { vdiskname: 'ansible-host1-vdisk1', hostname: 'ansible-host1' }
- { vdiskname: 'ansible-host2-vdisk1', hostname: 'ansible-host2' }

7. For more example see GitHub Repo. ☁️

Ansible-virtualize-playbooks

  • Use Gitclone or download the repo from github
  • Read the readme.
  • Change the values in examples/vars/specv_vars.yml
  • Check out the the playbooks in the examples folder.
  • Contribute to examples 😃

8. Encrypt Spectrum Virtualize Password 🔐

There is several ways to encrypt variables, text, passwords. with Ansible Vault.

One easy way to encrypt your password is using using the command ansible-vault and the encryption-string. This will encrypt the string/password.
And with the -ask-vault-pass option you will set a password to unlocked your secret. This can also be a file vault-password file.

$ ansible-vault encrypt_string mysuperduperpassword  --ask-vault-passNew Vault password: 
Confirm New Vault password:
!vault |
$ANSIBLE_VAULT;1.1;AES256
393536393666353331323730353836306262653735313838646263633531633361633561366333326531386530393239356434366137323364353065626130350a646430343865363830653233303562323362343465303235326637346333343063323636656239333339383133663261326536353731643836366463336436640a30613863656135326363656362373932323037313234623737633663313639366662613565656439626233663937653936366564653937613262373037353264
Encryption successful

Then you just past inn the value from !vault | Into the password variable in your Ansible playbook or vars file.

vars:
clustername: specvip
username: superuser
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
323663646162396664333836343263386466663634623865353639393034313337383732626335663461343237303731636534306633393265353032313136310a663966383339373064306435343561333337363836656632363732373065313265323739626463376330366362383236393035313031646365646461366163620a613164656133363537393136633166623362386638366166356162373161
6433
state: present

You will then need to use the -ask-vault-pass option to unlock the secret/password so that ansible can read it.
the password can also be writen into the file.

$ ansible-playbook playbook.yml -ask-vault-pass
Vault password: < Your Vault password!

There is also other option to use, Ansible Encrypted files that we can read variables from, vault-id. I will cover more on this in the next part.

9. Limitation in the Modules 🚧 🏗

At the moment there is limitation in the Ansible modules.
Example: We can only create thick volumes, no host-cluster.

However, this is first release and more is coming.

Update. 16.04.21. — There is now more support.
Support for:
- HyperSwap, Standard Mirror. Thick and Thin.
- Remote Copy (Global Mirror, Metro Mirror, Global Mirror with Change Volume)
- FlashCopy

--

--

Ole Kristian Myklebust
Possimpible

Nerd, Loves the mountains and all that come with it. IBMer that works for IBM Lab Services. My own Words and opinion.