Ansible is a simple yet powerful IT automation engine that helps users automates day-to-day repetitive tasks. Adding Ansible Towers or AWX to this powerful engine will give users role-based access to perform tasks and leverage other features like scheduling, creating workflows and more. In this blog post, I will be talking about how you can configure Ansible AWX for StorageGRID Ansible modules.
- Access to an Operating System with Ansible installed.
- StorageGRID account with management privilege.
On your machine that has ansible installed, install AWX using docker compose by following the steps on their webpage. Once you have installed AWX you should be able to access the AWX webpage using the default URL http://localhost and the default administrator username is admin, and the password is password. Now we have to install StorageGRID ansible modules in the awx_task docker container so AWX can access them. Follow the steps below to install StorageGRID Ansible modules in the docker container.
Connect to awx_task container
$ docker exec -it awx_task bash
Install Ansible modules in awx_task container
bash-4.4# ansible-galaxy collection install netapp.storagegrid -p /usr/share/ansible/collections
Log out of the container
Now that we have installed the StorageGRID Ansible modules, let’s create a project in AWX. A project is nothing but a logical collection of playbooks in AWX. You can manage playbooks and by either placing them in a folder on your Ansible Machine (default path /var/lib/awx/projects/), or by placing your playbooks into a source code management (SCM) system supported by AWX which includes Git, Subversion, Mercurial, and Red Hat Insights.
To create a project, click on “Projects” on the left-hand of AWX menu under the “RESOURCES” section. Select the green “+” button from the top right, this will open the add a Project screen. I have a public GitHub repo that I will use for this example for playbooks and you can use the same if you want to follow along exactly.
NAME – StorageGRID Automation
DESCRIPTION – Perform Day-Day tasks on StorageGRID
ORGANIZATION – Default
SCM TYPE – Git
SCM URL – https://github.com/NetApp-StorageGRID/StorageGRID-Ansible-AWX
After entering these values, click the green ‘SAVE’ button in the bottom right corner of the ‘NEW PROJECT’ section. This would pull in a copy of playbooks from the SCM repo as well.
Now we have a project that has the playbooks populated in it. Let’s create job templets with these playbooks we have at our disposal. To create Job Templets, click on “TEMPLATES” on the left-hand of AWX menu under the “RESOURCES” section.
Name – Update DNS on StorageGRID
Description – Optional
Job Type – Run
Inventory – Demo Inventory (* This is a default inventory on AWX. These playbooks use localhost as the ‘hosts’ so a custom Inventory isn’t needed)
Project – StorageGRID Automation
Playbook – sg_grid_dns.yml (* This drop-down is generated from the SCM pull when we created the project.)
Click the green ‘SAVE’ button.
We are almost ready to run the template, but we still need to do a few more things, if you look at the playbook sg_grid_dns.yml we are using a variable “dns_servers” that is not defined anywhere so need to define them by adding a survey to our template.
To add a survey in the template, click on the “ADD SURVEY” button at the top of Update DNS on StorageGRID templet.
Prompt: What are the IP addresses of DNS?
Answer Variable Name: dns_servers
Answer Type: Textarea
Default Answer: 126.96.36.199,188.8.131.52
Click on +ADD and the SAVE.
One last thing we need to provide is the grid info and you can add this in the extra variable section in the bottom of the page, would look something as follows.
grid_admin_base_url: https://<StorageGRID endpoint>/
Now that we have defined all the variables, click on Save and launch the templet by clicking the blue LAUNCH button. This will execute the nac_sg_grid_dns.py ansible module under the covers and update the DNS IPs on your StorageGRID.
In this GitHub repo, there are several other YAML files, I recommend playing with other plays for more hands-on experience. Few other things to consider in AWX are workflows templates to run jobs in a serial or parallel fashion, Scheduling tasks or workflow for a particular time, or repeat in an iterative fashion, and role based access in the organization section.