How to get started automating Pure Storage FlashArray and FlashBlade tasks with Ansible

Introduction

If you have been following my blog for a few years you may have already read some of my blogs on Ansible, or used seen some demos or even pulled some Ansible code from my GitHub repo

I was recently asked How can I learn more about Ansible, and the how can I start automating Pure Storage tasks with Ansible ?

So in response to that question, here’s a new post to provide a quick guide to help setting up an educational environment to explore automating Pure Storage FlashArray and FlashBlade tasks with Ansible.

This post includes:

Preparation

Let’s start by creating an Oracle Linux 7.9 server using VirtualBox and Vagrant

To check if VirtualBox is installed and version use the vboxmanage –version command.

% vboxmanage --version
6.1.32r149290

And to confirm the status and version of Vagrant use vagrant -v for example

% vagrant -v
Vagrant 2.2.19

Build Linux Server

Use the vagrant box list command to see if/what boxes you have installed, for example.

% vagrant box list 
oraclelinux/7             (virtualbox, 7.8.142)

Vagrant Box Add

To add a vagrant box use vagrant box add for example.

% vagrant box add https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json

Or if you want to get Oracle Linux 8 try.

% vagrant box add https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json
==> box: Loading metadata for box 'https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json'
==> box: Adding box 'oraclelinux/8' (v8.5.320) for provider: virtualbox
    box: Downloading: https://yum.oracle.com/boxes/oraclelinux/ol8/OL8U5_x86_64-vagrant-virtualbox-b320.box
    box: Calculating and comparing box checksum...
==> box: Successfully added box 'oraclelinux/8' (v8.5.320) for 'virtualbox'!

Upgrade Vagrant Box

For this post I will upgrade my Oracle Linux 7.8 box to 7.9.

% vagrant box update --box oraclelinux/7
Checking for updates to 'oraclelinux/7'
Latest installed version: 7.8.142
Version constraints: > 7.8.142
Provider: virtualbox
Updating 'oraclelinux/7' with provider 'virtualbox' from version
'7.8.142' to '7.9.324'...
Loading metadata for box 'https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json'
Adding box 'oraclelinux/7' (v7.9.324) for provider: virtualbox
Downloading: https://yum.oracle.com/boxes/oraclelinux/ol7/OL7U9_x86_64-vagrant-virtualbox-b324.box
Calculating and comparing box checksum...
Successfully added box 'oraclelinux/7' (v7.9.324) for 'virtualbox'!

Initialise Vagrant

Create a new environment and Vagrantfile in with vagrant init, for example

% mkdir vagrant-ol79
% cd vagrant-ol79
% vagrant init oraclelinux/7 
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

A cool Vagrant feature is that if you have not already pulled a box image you can get init to do it for you, as below.

% vagrant init oraclelinux/7 https://oracle.github.io/vagrant-projects/boxes/oraclelinux/7.json
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Alternatively for Oracle Linux 8 use.

% vagrant init oraclelinux/8 https://oracle.github.io/vagrant-projects/boxes/oraclelinux/8.json
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Start Vagrant Machine

And start the VirtualBox virtual machine.

% vagrant up --provider=virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'oraclelinux/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'oraclelinux/7' version '7.9.324' is up to date...
==> default: Setting the name of the VM: vagrant-ol79_default_1648136667554_7114
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
... 
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/rekins/vagrant-ol79 

Install Ansible

Shell into Vagrant Machine using vagrant ssh, change to root, and install Ansible, for example.

% vagrant ssh

Welcome to Oracle Linux Server release 7.9 (GNU/Linux 5.4.17-2136.302.7.2.2.el7uek.x86_64)

[vagrant@localhost ~]$ sudo su -
[root@localhost ~]# yum install ansible
...

[vagrant@localhost ~]$ ansible --version
ansible 2.9.27
  config file = /home/vagrant/ansible.cfg
  configured module search path = [u'/home/vagrant/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Mar 12 2021, 14:55:44) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)]

Install Pure SDKs

Install the Pure Storage Python SDK using pip, for example.

[root@localhost ~]# yum install python-pip
...
[root@localhost ~]# pip install purestorage
Collecting purestorage
...
Successfully installed certifi-2021.10.8 chardet-4.0.0 purestorage-1.19.0 requests-2.27.1 urllib3-1.26.9

[root@localhost ~]# pip install purity_fb
Collecting purity_fb
...
Successfully installed purity-fb-1.12.3 python-dateutil-2.8.2 six-1.16.0

Install Pure Collections

Install the FlashBlade Collection using ansible-galaxy collection install

[vagrant@localhost ~]$ ansible-galaxy collection install purestorage.flasharray
Process install dependency map
Starting collection install process
Installing 'purestorage.flasharray:1.12.1' to '/home/vagrant/.ansible/collections/ansible_collections/purestorage/flasharray'

And again for the FlashBlade Collection

[vagrant@localhost ~]$ ansible-galaxy collection install purestorage.flashblade
Process install dependency map
Starting collection install process
Installing 'purestorage.flashblade:1.9.0' to '/home/vagrant/.ansible/collections/ansible_collections/purestorage/flashblade'

Pure Storage FlashArray

If you don’t know / have a FlashArray API token, logon to the FlashArray and using the CLI obtain an API token using pureadmin list –api-token –expose, for example

pureuser@z-m20-a> pureadmin list --api-token --expose
Name                Type   API Token                             Created                  Expires                
...                    
pureuser            local  5d8ad02f-547d-fc24-bb51-fa0d2b0de123 2019-03-15 09:00:57 GMT  -                      
...

Create an Ansible playbook, using the Pure Storage FlashArray collection, for example fa_demo.yaml

- name: Pure Storage FlashArray Ansible module Demo
  hosts: localhost 
  collections:
    - purestorage.flasharray

  gather_facts: false

  tasks:

  - name: Create new FlashArray Volume
    purefa_volume:
      name: "Vagrant-Demo"
      size: "1T"
      fa_url: "10.225.112.80"
      api_token: "5d8ad02f-547d-fc24-bb51-fa0d2b0de123"

Run playbook with ansible-playbook <filename>

[vagrant@localhost ~]$ ansible-playbook fa_demo.yaml -i hosts

PLAY [Pure Storage FlashArray Ansible module Demo] ***********************************************************************************************

TASK [Create new FlashArray Volume] ***********************************************************************************************
changed: [localhost]

PLAY RECAP ************************************************************************************
localhost  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Logon to the FlashArray and navigate to Storage -> Volumes to see the newly created volume

FlashArray Volume

FlashArray module documentation, syntax and examples are available at docs.ansible.com

Pure Storage FlashBlade

Let’s do the same again, but this time using a FlashBlade.

Again, if you don’t know / have a FlashBlade API token, logon to the FlashBlade and use the CLI to obtain an API token using pureadmin list –api-token –expose, for example

pureuser@fbstaines01> pureadmin list --api-token --expose
Name                Type    Role         API Token                               Created                  pureuser            local   array_admin  T-2b74f9eb-a35f-40d9-a6a6-22c13775a53c  2020-05-08 06:00:24 BST  -

Create an Ansible playbook, using the Pure Storage FlashBlade collection, for example fb_demo.yaml

- name: Pure Storage FlashBlade Ansible module Demo
  hosts: localhost 
  collections:
    - purestorage.flashblade

  gather_facts: false

  tasks:

  - name: Create new FlashBlade FileSystem
    purefb_fs:
        fb_url: "10.225.112.69"
        api_token: "T-2b74f9eb-a35f-40d9-a6a6-22c13775a53c"
        name: "Vagrant-Demo"
        state: present
        size: 1T
        nfsv3: True
        nfsv4: False
        hard_limit: true
        nfs_rules: '*(rw,no_root_squash)'
        snapshot: True

Run playbook with ansible-playbook <filename>

[vagrant@localhost ~]$ ansible-playbook fb_demo.yaml -i hosts

PLAY [Pure Storage FlashBlade Ansible module Demo] *************************************************************************************

TASK [Create new FlashBlade FileSystem] *************************************************************************************
changed: [localhost]

PLAY RECAP **************************************************************************
localhost  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Logon to the FlashBlade and navigate to Storage -> File Systems to see the newly created file system

FlashBlade File System

FlashBlade module documentation, syntax and examples are available at docs.ansible.com

Summary

In this short post I have shared how we can use Vagrant and VirtualBox to create an Oracle Linux 7.9 server for use as an educational Ansible control machine and, how we can use the Pure Storage Ansible modules to automate FlashArray and FlashBlade tasks.

If you want to learn more or see Ansible in action check-out my Oracle Rapid Cloud Automation (ORCA) Ansible playbook or YouTube demo.

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

One thought on “How to get started automating Pure Storage FlashArray and FlashBlade tasks with Ansible

Add yours

Leave a Reply

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: