This post is part of the Automating your Pure Storage Infrastructure series.
    Using Ansible to Provision your Pure Storage Infrastructure

Using Ansible to Provision your Pure Storage Infrastructure

Share on:

I mentioned previously that there are many things I love about the Pure Storage Flasharray, but one of my favorite is how easy it is to integrate into different automation solutions. In this blog I will cover how to use Ansible to provision your Pure Storage Infrastructure.

Information on the Pure Storage Ansible Integration

The official site has information on the integration and the documentation is a great place on how to learn to use the integration. Are you looking for examples? Then checkout GitHub.

Installing and Setting up the Ansible Integration

  1. Install Python
  2. Install Ansible
  3. Install Pure Storage Python package by running pip install purestorage
  4. Install Pure Storage Ansible Provider by running ansible-galaxy collection install purestorage.flasharray

Using Ansible to Provision your Pure Storage Infrastructure

Below is a sample ansible playbook that will create a volume, two hosts with an ISCSI iqn and then add the hosts and volume to a hostgroup.

 1- name: Configure Pure Storage Environment
 2  hosts: localhost
 3  collections:
 4  - purestorage.flasharray
 5  gather_facts: yes
 6  vars:
 7    fa_url: 192.168.1.10
 8    fa_api_token: apitokenhere-00000000
 9  tasks:
10  - name: Create Volume
11    purefa_volume:
12      name: david-ansible-test
13      size: 10G
14      fa_url: "{{fa_url}}"
15      api_token: "{{fa_api_token}}"
16  - name: Create Host1
17    purefa_host:
18      host: "david-ansible-host1"
19      protocol: iscsi
20      iqn: "iqn.1998-01.com.vmware:david-ansible-host1"
21      fa_url: "{{fa_url}}"
22      api_token: "{{fa_api_token}}"
23  - name: Create Host2
24    purefa_host:
25      host: "david-ansible-host2"
26      protocol: iscsi
27      iqn: "iqn.1998-01.com.vmware:david-ansible-host2"
28      fa_url: "{{fa_url}}"
29      api_token: "{{fa_api_token}}"
30  - name: Create Hostgroup
31    purefa_hg:
32      hostgroup: david-ansible-hostgroup
33      fa_url: "{{fa_url}}"
34      api_token: "{{fa_api_token}}"
35  - name: Add hosts to hostgroup and connect volume
36    purefa_hg:
37      hostgroup: david-ansible-hostgroup
38      host:
39        - "david-ansible-host1"
40        - "david-ansible-host2"
41      volume: "david-ansible-test"
42      fa_url: "{{fa_url}}"
43      api_token: "{{fa_api_token}}"

Using Ansible to Cleanup your Pure Storage Infrastructure

Below is a sample ansible playbook that will destroy the volume, hosts and hostgroup that were previously created. Don’t forget to update your fa_url and fa_api_token variables.

 1- name: Destroy configured Pure Storage Environment
 2  hosts: localhost
 3  collections:
 4  - purestorage.flasharray
 5  gather_facts: yes
 6  vars:
 7    fa_url: 192.168.1.10
 8    fa_api_token: apitokenhere-00000000
 9  tasks:
10  - name: Remove hosts from hostgroup and disconnect volume
11    purefa_hg:
12      hostgroup: david-ansible-hostgroup
13      host:
14        - "david-ansible-host1"
15        - "david-ansible-host2"
16      volume: "david-ansible-test"
17      fa_url: "{{fa_url}}"
18      api_token: "{{fa_api_token}}"
19      state: absent
20
21  - name: Remove Volume
22    purefa_volume:
23      name: david-ansible-test
24      fa_url: "{{fa_url}}"
25      api_token: "{{fa_api_token}}"
26      state: absent
27      eradicate: false
28
29  - name: Remove Host1
30    purefa_host:
31      host: "david-ansible-host1"
32      fa_url: "{{fa_url}}"
33      api_token: "{{fa_api_token}}"
34      state: absent
35
36  - name: Remove Host2
37    purefa_host:
38      host: "david-ansible-host2"
39      fa_url: "{{fa_url}}"
40      api_token: "{{fa_api_token}}"
41      state: absent
42
43  - name: Remove Hostgroup
44    purefa_hg:
45      hostgroup: david-ansible-hostgroup
46      fa_url: "{{fa_url}}"
47      api_token: "{{fa_api_token}}"
48      state: absent

Running your Ansible Playbook

The examples above can be found here

To configure your infrastructure run:

1ansible-playbook ./StorageConfiguration.yaml

To cleanup the infrastructure we configured run:

1ansible-playbook ./DestroyStorageConfiguration.yaml

Its that easy!

Closing

Ansible is a great tool when it comes to automation! Its extensibility across multiple platforms and integrations makes it an ideal candidate for use in many environments.

Any questions or comments? Leave them below.

comments powered by Disqus

See Also