Introduction
Introduction to the Rubrik Modules for Ansible
Rubrik's API first architecture enables organizations to embrace and integrate Rubrik functionality into their existing automation processes. While Rubrik APIs can be consumed natively, companies are at various stages in their automation journey with different levels of knowledge on staff. The Rubrik Modules for Ansible extends upon the RubrikPython SDK, transforming Rubrik API functionality into easy to consume Ansible modules which eliminates the need to create inidividual automation scripts and extends upon one of Rubrik's main design centers - simplicity.
Authentication Mechanisms
The Rubrik Modules for Ansible provides two mechanisms for supplying credentials to the Ansible modules. Credentials may be accessed through the use of environment variables or manually passed into the each module task as variables.
Authenticating with Environment Variables
Storing credentials in environment variables is a more secure process than directly hard coding them into Playbooks and ensures that your credentials are not accidentally shared if your code is uploaded to an internal or public version control system such as GitHub. If no arguments are manually passed to the Ansible module, it will attempt to read the Rubrik cluster credentials from the following environment variables:
rubrik_cdm_node_ip
(Contains the IP/FQDN of a Rubrik node)rubrik_cdm_username
(Contains a username with configured access to the Rubrik cluster)rubrik_cdm_password
(Contains the password for the above user)rubrik_cdm_token
(Contains the the API token used for authentication)
Setting Environment Variables in macOS and *nix
For macOS and *nix based operating systems the environment variables can be set utilizing the export command as follows:
In order for the environment variables to persist across terminal sessions, add the above three export commands to the ~\.bash_profile
or ~\.profile
file and then run source ~\.bash_profile
or source ~\.profile
to ensure the environment variables are present in your current terminal session..
Once set, the Ansible modules will automatically utilize the data within the environment variables to perform its connection unless credentials are specifically passed in the arguments of the module.
Authenticate by Providing Username and Password or API Token
Rubrik Modules for Ansible Quick Start
The following section outlines how to get started using the Rubrik Modules for Ansible, including installation, configuration, as well as sample code.
Prerequisites
The following are the prerequisites in order to successfully install and run the sample code included in this quickstart guide:
Ansible (tested agains v2.7.6)
Python (Tested against v2.7.6 and v3.7.4)
Rubrik CDM
Installation
Install the Rubrik SDK for Python
pip install rubrik_cdm
Install with Git
Clone the GitHub repository to a local directory
git clone https://github.com/rubrikinc/rubrik-modules-for-ansible.git
Install with Ansible Galaxy
ansible-galaxy collection install rubrikinc.cdm
NOTE: If you install via Ansible Galaxy, you will need to reference the modules names as their fully qualified name by prepending
rubrikinc.cdm
to the beginning of the module name. For example,rubrikinc.cdm.rubrik_on_demand_snapshot
.
Configuration
The cloned repository includes a ansible.cfg
file that is pre-configured with the correct paramaters to run the Ansible modules from the local directory.
Sample Syntax - vSphere Virtual Machine On-Demand Snapshot
Setting up the Sample Workflow
Create a file named rubrik.yml
in your working directory and copy in the following code:
NOTE: If you installed via Ansible Galaxy, you will need to reference the module names as its fully qualified name by prepending
rubrikinc.cdm
to the beginning of the module name. In this case,rubrikinc.cdm.rubrik_on_demand_snapshot
.
Breaking Down the Sample Workflow
This section of code represents generic "Ansible" related configurations:
hosts:
corresponds to the inventory you wish to run the Ansible module against. In this case, we are providing that information through environment variables so we only need to definelocalhost
in this field.connection:
corresponds to the connection plugin you wish to use in your module. Since we want to execute the Playbook on the local machine we want to use thelocal
connection.gather_facts:
can be used to gather facts about remote hosts. Since we're running the Ansible Module on the local machine we do not need to gather this information. Setting this value tofalse
is optional but recommended.
Once the Ansible specific configurations are in place we need to define the name of the vSphere VM we wish to take a on-demand snapshot of.
The final section in the example is the on-demand snapshot task.
In this example, we are automatically importing the Rubrik cluster credentials through pre-defined environment variables so there is no need to define them in the task.
rubrik_on_demand_snapshot
is the specific Ansible module we wish to use. See the note above regarding module naming if you installed via Ansible Galaxy.object_name
is one of the define paramagters of therubrik_on_demand_snapshot
module and is referencing the previously definedvm_name
variable.
Running the Sample Workflow
Once rubrik.yml
is saved within the working directory, execute the Playbook with the following statement:
Contributing to the Rubrik Modules for Ansible
The Rubrik Modules for Ansible is hosted on a public repository on GitHub. If you would like to get involved and contribute to the Ansible Modules please follow the below guidelines.
Common Environment Setup
Clone the Rubrik Modules for Ansible repository
Change to the repository root directory
Switch to the devel branch
New Module Development
The /rubrik-modules-for-ansible/library
directory contains all of the Rubrik Ansible modules. You can also utilize the following file as a template for all new modules:
To add paramters specific to the new module you can update the following section which starts on line 60
:
After the new variables have been defined you can start adding any new required logic after the code block section.
Your final Rubrik Python SDK call should be added to Line 93
.
For example, if you wanted to call the cluster_version()
function the line would look like:
Once the module has been fully coded you can use the following script to automatically generate the module DOCUMENTATION
block:
To use the script, update the filename =
variable and then run python create_documentation_block.py
Further Reading
Last updated
Was this helpful?