Getting Started with the Nutanix Ansible module – Nutanix.dev (2024)

In March 2022 Nutanix released the first generally available (GA) version of our Ansible module. This release allowed our customers and partners to easily integrate the Nutanix Cloud Platform configurations and changes into deployment workflows. For example, the March 2022 release provided access to the following Nutanix Cloud Platform entities (and others, that we’ll talk about shortly):

  • VPCs
  • Subnets
  • Floating IPs

At the simplest level, it is easy to see how CRUD operations can be carried out against this small collection of entities alone, allowing workflow-based configuration at any stage of deployment.

Today’s article will show how to get started with the Nutanix Ansible module.

Installation

The steps in this document somewhat mirror the installation documentation from the Github repository, but with the addition of Ansible Vault. Please follow along with this article if you’d like start from scratch and end up with a basic working Ansible configuration for use with the Nutanix Ansible module. If you’d like to just download the complete results of this process, you may do so by cloning the demo repository.

These steps have been written for use with almost any Linux environment, but should work on OS X with very little modification. Some changes may be required for use in a Windows environment.

Prerequisites

To use these steps, you’ll need the following software installed:

  • Git, to clone the Nutanix Ansible module from GitHub
  • Ansible, to manage and run our Ansible playbook and manage our encrypted Ansible Vault data. Note: We will be working with a local configuration only; there’s no need to setup a dedicated control node in order to follow these steps. Ansible version 2.13.1 was used for this article.
  • Once Ansible is installed, verify the ansible-galaxy, ansible-vault and ansible-playbook commands are available.
  • A connection to a Nutanix Cloud Platform cluster. AOS version 6.0.2.4 was used for this article.
  • A connection to a Nutanix Prism Central instance. Version pc.2022.1 was used for this article.

Installing the Nutanix Ansible Module

In July 2022 Nutanix released v1.4.0 of our Nutanix Ansible module; this is the version we’ll use throughout this article. The commands below were used to download, build and install the Nutanix Ansible module.

# enter home directorycd ~# optional, but recommended: change to an existing working directory for our projectscd Data/solutions/nutanix# download the Nutanix Ansible sourcegit clone https://github.com/nutanix/nutanix.ansible.gitcd nutanix.ansiblegit checkout v1.4.0 -b v1.4.0# optional, but recommended: create and activate a python virtual environmentpython -m venv venv. venv/bin/activate# build and install the collectionansible-galaxy collection buildansible-galaxy collection install nutanix-ncp-1.4.0.tar.gz

The screenshot below shows the above process.

Getting Started with the Nutanix Ansible module – Nutanix.dev (1)

Demo Configuration

Now that we have Ansible and the Nutanix Ansible module installed, we can continue with the build of our demo project.

Note: Ansible Vault has been used to work with local files in this demo. If you have an alternative and preferred Ansible Vault configuration you may wish to alter these steps to suit your environment.

The steps below assume your terminal’s current directory is still the same directory as the module’s downloaded source. However, you may wish to complete these steps in a dedicated directory.

  • Create and enter a subdirectory for the demo files
mkdir democd demo
  • Create Ansible Vault password file
# change the command below so that your preferred password is usedecho 'your_password_here' > .vault_pass# ensure the .vault_pass file is never added to source controlecho .vault_pass > .gitignore
  • Create Ansible hosts file named hosts. This demo uses a host group named dev, but you may name the group anything you like. The hosts file contents should be as follows:
[dev]localhost ansible_connection=local
  • Create the Ansible configuration file named ansible.cfg. The contents of this file should be as follows:
[defaults]inventory = ./hostsvault_password_file = ./.vault_pass
  • Create a directory structure for our demo’s Ansible variables.
mkdir -p ./group_vars/dev
  • Create the Ansible variables file for the public variables. Sensitive information e.g. credentials should not be stored here. For this project, this file is group_vars/dev/vars and should contain the following; change your_prism_central_ip_address_here to match your environment:
---# public datapc_ip: your_prism_central_ip_address_here
  • Use Ansible Vault to create the encrypted file containing our sensitive data. For this demo, this encrypted file will contain the username and password for connection to Prism Central.
ansible-vault create group_vars/dev
  • The above command will launch your chosen editor which can then be used to set the contents of the vault file as follows (change the variable values as necessary):
---# sensitive datavault_pc_username: your_prism_central_username_herevault_pc_password: your_prism_central_password_here

Viewing the contents of the vault file after saving will show encrypted contents only. If you need to edit the variable values later, use the following command:

ansible-vault edit group_vars/dev/vault

Demo Playbooks

With the Nutanix Ansible module installed and our demo environment configured, we can start writing Ansible playbooks that utilise the new module.

Test Playbook #1: Get Clusters Info

The playbook below is a modified version of clusters_info.yml provided with the source from GitHub, but with the following changes:

  • The playbook makes use of the encrypted credentials in group_vars/dev/vault
  • An additional task has been added that shows the output of our Ansible tasks
  • To continue, create a new file named clusters_info.yml and add the following contents to the file:
---- name: Clusters_Info playbook hosts: localhost gather_facts: false collections: - nutanix.ncp module_defaults: group/nutanix.ncp.ntnx: nutanix_host: "{{ pc_ip }}" nutanix_username: "{{ vault_pc_username }}" nutanix_password: "{{ vault_pc_password }}" validate_certs: false tasks: - name: test getting all clusters ntnx_clusters_info: register: clusters - name: test getting particular cluster using uuid ntnx_clusters_info: cluster_uuid: '{{ clusters.response.entities[0].metadata.uuid }}' register: result - name: List clusters using length, offset, sort order and priority sort attribute ntnx_clusters_info: length: 2 offset: 0 sort_order: "ASCENDING" sort_attribute: "name" register: result - name: Print cluster list ansible.builtin.debug: var: result when: result is defined

With the first test playbook created, it can be tested using our entire Ansible configuration.

ansible-playbook clusters_info.yml

If the connection to Prism Central was successful, the output of the clusters list module will be displayed. This output can be extensive but will end with something similar to the screenshot shown below.

Getting Started with the Nutanix Ansible module – Nutanix.dev (2)

Test Playbook #2: Create Prism Central Categories

The next demo playbook is again a modified version of one provided in the official GitHub repository. This time we are creating Prism Central Categories; please see the official categories documentation for detailed information.

  • Create a new file named create_categories.yml and set the file contents as follows:
---- name: Create Prism Central categories playbook hosts: localhost gather_facts: false collections: - nutanix.ncp module_defaults: group/nutanix.ncp.ntnx: nutanix_host: "{{ pc_ip }}" nutanix_username: "{{ vault_pc_username }}" nutanix_password: "{{ vault_pc_password }}" validate_certs: false tasks: - name: task to create category keys ntnx_categories: state: "present" name: "nutanix_ansible" desc: "Category key created with Nutanix Ansible module" register: create_key - name: task to create category values ntnx_categories: state: "present" name: "nutanix_ansible" values: - "registered" - "unregistered" register: create_values - name: Print result ansible.builtin.debug: var: create_values when: create_values is defined
  • If the connection to Prism Central was successful, the output of creating Prism Central categories will be displayed. The indicator of success during this test, assuming a matching category doesn’t already exist, is the indication that 2 changes were made. See the screenshot for an example.
Getting Started with the Nutanix Ansible module – Nutanix.dev (3)

Likewise, if we were to run the same playbook again, the configuration management capabilities of Ansible would ensure no changes were made. This is due to the fact that the nominated category values and keys already exist:

Getting Started with the Nutanix Ansible module – Nutanix.dev (4)

Wrapping Up

Using the Nutanix Ansible module, it’s easy to see how quickly a required configuration can be deployed. The two examples shown here are just a few of the available entities that can be managed using this module; for full information, please see the official Nutanix Ansible GitHub repository.

A complete and downloadable copy of the Ansible configuration used throughout this article can be downloaded from the NutanixDev GitHub repository.

Thanks for reading and have a great day. 🙂

Related Resources

Getting Started with the Nutanix Ansible module – Nutanix.dev (2024)

FAQs

How to set up Ansible? ›

How to Install Ansible?
  1. Step 1: Update Your Control Node. ...
  2. Step 2: Install EPEL Repository. ...
  3. Step 3: Install Ansible. ...
  4. Step 4: Create a User for Ansible. ...
  5. Step 5: Configure Our Admin User for SSH Access. ...
  6. Step 6: Create an Inventory. ...
  7. Step 7: Create an Ansible Playbook. ...
  8. Step 8: Run the Playbook.
Feb 21, 2023

How do I run Ansible modules locally? ›

There are four ways to run ansible playbook locally and we have listed them all here.
  1. Method1: Specify Localhost in your hosts directive of your playbook.
  2. Method2: Using local_action clause in the ansible playbook.
  3. Method3: Add an entry in your Inventory.
  4. Method4: Specify in the Ansible Command line.
Jan 25, 2023

How do I create an Ansible playbook structure? ›

Creating a playbook
  1. Open a terminal window on your control node.
  2. Create a new playbook file named playbook. yaml in any directory and open it for editing.
  3. Add the following content to playbook.yaml : ...
  4. Run your playbook.

How do I access my AWX dashboard? ›

Open your browser and go to http://awx-server.com and then log in to the AWX server using the default credentials (user name: admin, password: password).

Is Ansible good for beginners? ›

Simple: As we've seen, Ansible uses a very simple syntax written in YAML known as playbooks—YAML (Yet Another Markup Language) is a human-readable data serialization language. We don't need special coding skills to code and understand playbooks. It is very easy to install and execute tasks in order.

Is Ansible easy to setup? ›

Free: Ansible is an open-source tool. Very simple to set up and use: No special coding skills are necessary to use Ansible's playbooks (more on playbooks later). Powerful: Ansible lets you model even highly complex IT workflows.

What are the two types of modules in Ansible? ›

Ansible supports two assembler frameworks: Ansiballz and the older Module Replacer.

How do I know if Ansible module is installed? ›

Checking if the Ansible collection is installed or not
  1. Open the terminal application.
  2. Then type the ansible-galaxy collection list command and press the [Enter] key to display a list of all installed collection on your Linux or Unix machine. ...
  3. To filter out results use the grep command or egerp command as per your needs.
May 13, 2022

How do you run Ansible in pipeline? ›

Select Ansible-CD and click Edit pipeline. Select Azure Dev stage and click View stage tasks to view the pipeline tasks. You will see the tasks as below. Select the Replace Tokens task.

What is the difference between Ansible and Ansible playbook? ›

An Ansible playbook is an organized unit of scripts that defines work for a server configuration managed by the automation tool Ansible. Ansible is a configuration management tool that automates the configuration of multiple servers by the use of Ansible playbooks.

What language is used in Ansible? ›

Ansible is a tool written in Python, and it uses the declarative markup language YAML to describe the desired state of devices and configuration.

How do I write code in Ansible? ›

End
  1. Playbooks are written in the YAML format and have a . yml file extension.
  2. Use this command to run a playbook: $ ansible-playbook <playbook. ...
  3. Use this command to check the playbook for syntax errors: $ ansible-playbook <playbook. ...
  4. Create lists. ...
  5. Include whitespaces. ...
  6. Name your tasks. ...
  7. Include the state. ...
  8. Employ comments.
Feb 1, 2023

What is the difference between AWX and Ansible? ›

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is the upstream project for Tower, a commercial derivative of AWX. Ansible Towers powers enterprise automation by adding control, security and delegation capabilities to Ansible environments.

Is there a GUI for Ansible? ›

Ansible Tower also allows a user to execute remote tasks from a graphical user interface (GUI).

What does AWX mean Ansible? ›

The AWX project—AWX for short—is an open source community project, sponsored by Red Hat, that enables users to better control their community Ansible project use in IT environments. AWX is the upstream project from which the automation controller component is ultimately derived.

How many days IT will take to learn Ansible? ›

Yes, you can complete this free Ansible basics within 90 days.

What is the best way to learn Ansible? ›

6 Best Online Courses to learn Ansible for DevOps in 2023
  1. Ansible for the Absolute Beginner — Hands-On — DevOps. ...
  2. Mastering Ansible [Udemy] ...
  3. Mastering Ansible Automation — Step by Step. ...
  4. Ansible Advanced — Hands-On — DevOps. ...
  5. Hands-on Ansible [Pluralsight] ...
  6. Ansible: Zero to Production Ready [Educative]

Does Ansible need coding? ›

Ansible is a free, open-source tool, and it's straightforward to set up and use: Ansible's playbooks don't require any special coding knowledge. Ansible can be used to perform simple tasks such as ensuring that a service is operating or rebooting from the command line without the need for configuration files.

What is Ansible for beginners? ›

Ansible® is an open source IT automation engine that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes.

What is the disadvantage of Ansible? ›

Ansible disadvantages include debugging, performance, complex data structures and control flow. Complex data structures. Many network automation tasks require complex data structures. One of the first things I considered when learning Ansible was to use it to perform network discovery.

Is Python necessary for Ansible? ›

While you can write Ansible modules in any language, most Ansible modules are written in Python, including the ones central to letting Ansible work. By default, Ansible assumes it can find a /usr/bin/python on your remote system that is either Python2, version 2.6 or higher or Python3, 3.5 or higher.

How do I know which Ansible module to use? ›

Ansible has a very attractive command named ansible-doc. This command will tell all the module details installed in your system.

What are the most used modules in Ansible? ›

  • Module 2: Service. After installing a package, you need a module to start it. ...
  • Module 3: Copy. The copy module copies a file from the local or remote machine to a location on the remote machine. ...
  • Module 4: Debug. ...
  • Module 5: File. ...
  • Module 6: Lineinfile. ...
  • Module 7: Git. ...
  • Module 8: Cli_command. ...
  • Module 9: Archive.
Sep 11, 2019

What is the difference between Ansible module and plugin? ›

Plugins offer options and extensions for the core features of Ansible: transforming data, logging output, connecting to inventory, and more. Modules are a type of plugin that execute automation tasks on a 'target' (usually a remote system).

How do I install Ansible modules? ›

The quickest way is to simply have a folder called library/ in the same folder as your playbook. Inside this folder, place the python script for the Ansible Module. You should now have a corresponding task available to your playbook.

Where are the Ansible modules located? ›

/usr/share/ansible/plugins/modules/

Can I run Ansible in Docker? ›

Install Ansible in a Docker container. Use a Service Principal to authenticate Ansible to Azure from a Docker container. Run Ansible commands from a Docker container.

How do I deploy Ansible? ›

Install Ansible on the control host. Create an ansible user on both the control host and workstation host. Configure a pre-shared key for Ansible that allows the user to log in from control to workstation without a password. Configure the Ansible user on the workstation host so that Ansible may sudo without a password.

What is the difference between Ansible and terraform? ›

Terraform is a tool designed to help with the provisioning and deprovisioning of cloud infrastructure using an infrastructure as code approach. It is highly specialized for this purpose. On the other hand, Ansible is a more general tool that can be used for automation across various domains.

What is replacing Ansible? ›

SaltStack is configuration management and orchestration tool. It is one of the best Ansible alternatives that enables system administrators to automate server provisioning and management tasks. Features: This alternative to Ansible offers a simple programming interface. Prebuilt modules to support 100s of applications.

Does Ansible use JSON or YAML? ›

This page provides a basic overview of correct YAML syntax, which is how Ansible playbooks (our configuration management language) are expressed. We use YAML because it is easier for humans to read and write than other common data formats like XML or JSON.

Why Ansible is better than Jenkins? ›

For complex environments with a vast number of servers, Ansible would be the go-to tool. Its effective inventory management system helps manage the system better. For smaller tasks that involve calling multiple tools, like build, code quality analysis, and testing, Jenkins would be a better option.

What is better than Ansible? ›

Puppet Labs, Chef, Salt, Terraform, and Jenkins are the most popular alternatives and competitors to Ansible.

How many Ansible modules are there? ›

12 Useful & Common Ansible Modules.

What is difference between Ansible and Docker? ›

Ansible provides seamless application configuration, while Docker provides a containerized environment for building and deploying applications. Therefore, you should consider Docker for code shipping and deployment and Ansible for application configuration.

What is basic syntax of Ansible? ›

Ansible uses YAML syntax for expressing Ansible playbooks. This chapter provides an overview of YAML. Ansible uses YAML because it is very easy for humans to understand, read and write when compared to other data formats like XML and JSON. Every YAML file optionally starts with “---” and ends with “...”.

What are Ansible modules written in? ›

Modules can be written in any language, but most of the following guide is assuming you are using Python. Modules for inclusion in Ansible itself must be Python or Powershell.

Is Ansible better than Terraform? ›

In terms of use cases, Terraform is preferable for containerized solutions deployed for provisioning software within a cloud platform. In comparison, Ansible helps users gain reasonable control over enterprise devices and explore methods for deploying underlying components.

Is Ansible better than Kubernetes? ›

In other words, Ansible deploys changes to hosts, while Kubernetes manages containers and keeps them working properly. Ansible is an excellent useful tool for front-end developers, particularly in situations where some programming is required. Kubernetes is best suited to developing larger apps.

Can Ansible replace SCCM? ›

Ansible is not a replacement for System Center Configuration Manager (SCCM) or Chocolatey; it's a supplemental tool that allows you to automate the services your software provides.

Which UI is best for Ansible? ›

AWX is the most well-known and feature complete UI for Ansible. It provides a sleek and intuitive interface that neatly organizes the configuration options by category and allows for the use of Role-Based Access Control. This gives users the option to regulate who can see or modify certain settings and files.

How do I master Ansible? ›

What you'll learn
  1. Execute ad-hoc commands against servers using Ansible.
  2. Write Ansible configuration playbooks to deploy a 3-tier web application.
  3. Configure Ansible roles with tasks, handlers, files, templates, and default variables.
  4. Write operational playbooks to check cluster status and perform a cluster restart.

Can Ansible deploy VMs? ›

Ansible playbooks can deploy VMs from ISO images. However, one of the goals of automation is to speed up the deployment process, and using templates is indeed faster. If you have existing VMs, you can create templates from them. You can also deploy a barebones installation and use it as the basis for your template.

What database does Ansible use? ›

Database, installed with Ansible Automation Platform

This database consists of a PostgreSQL installation done on the controller node, hub node, or separate node as part of Ansible Automation Platform installation using PostgreSQL packages provided by Red Hat.

Is Ansible same as Python? ›

Ansible is written in the Python programming language and has a quite minimal learning curve. The procedure to set up Ansible is pretty simple and doesn't rely on any extra application, servers, or client daemons. Ansible is based on the principle of embracing the interrelation and architecture of the system.

What is YAML in Ansible? ›

YAML stands for Yet Another Markup Language. Ansible uses YAML syntax to express Ansible playbooks. Because compared to other data formats such as XML and JSON, it is very easy for people to understand, read, and write.

How do I set up Ansible host? ›

As we know that Ansible uses ssh for connecting to hosts. So we need to specify the username, password, or ssh key of those hosts. If all the servers have the same username and password/ssh-key, you can mention it in dev:vars label. If not you can specify it with the IP addresses separated by space as shown below.

How to setup Ansible on Windows? ›

To install Ansible on Windows using Cygwin, follow these steps:
  1. Download the Cygwin installation file. ...
  2. Run the Cygwin installation file. ...
  3. Select Install from Internet as the download source and click Next.
  4. In the Root Directory field, specify where you want the application installed, then click Next.
Sep 29, 2020

What is required to run Ansible? ›

Ansible 2.10 (or higher) installed. One or more network devices that are compatible with Ansible. Basic Linux command line knowledge. Basic knowledge of network switch & router configuration.

How do I set up Ansible automation platform? ›

  1. Preparing for the Ansible Automation Platform Installation. 1.1. Installation and Reference Guide. ...
  2. Download the Ansible Automation Platform Installation Program. 2.1. Using the Bundled Ansible Automation Platform Installer.
  3. Installing Ansible Automation Platform. 3.1. ...
  4. Import a Subscription.
  5. Congratulations.
May 3, 2022

Does Ansible need to be installed on remote host? ›

Ansible tasks run on the hosts that are (explicitly) specified; if you've specified a remote host, they're run on the remote host, but if you've specified localhost, they're run on localhost.

How does Ansible connect to remote hosts? ›

By default, Ansible connects to all remote devices with the user name you are using on the control node. If that user name does not exist on a remote device, you can set a different user name for the connection. If you just need to do some tasks as a different user, look at Understanding privilege escalation: become.

How do I run Ansible command? ›

The command module takes the command name followed by a list of space-delimited arguments. The given command will be executed on all selected nodes. The command(s) will not be processed through the shell, so variables like $HOSTNAME and operations like "*" , "<" , ">" , "|" , ";" and "&" will not work. Use the ansible.

What are the Windows prerequisites for Ansible? ›

Ansible requires PowerShell version 3.0 and . NET Framework 4.0 or newer to function on older operating systems like Server 2008 and Windows 7. The base image does not meet this requirement. You can use the Upgrade-PowerShell.

Why can't Ansible run on Windows? ›

No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host natively, though it can run under the Windows Subsystem for Linux (WSL). The Windows Subsystem for Linux is not supported by Ansible and should not be used for production systems.

Can Ansible automate Windows? ›

Red Hat Ansible Automation Platform provides a module for automating basic package management in Windows. It also integrates with Chocolatey software management automation for Windows to provide auto- mated idempotent package management.

What language does Ansible use? ›

Ansible is a tool written in Python, and it uses the declarative markup language YAML to describe the desired state of devices and configuration.

How do you practice Ansible? ›

Create a basic playbook for all servers in the Ansible inventory. Add a section to the playbook for the Network servers in the Ansible inventory. Add a section to the playbook for the SysAdmin servers in the Ansible inventory. Execute the playbook to verify your playbook works correctly.

What should I automate with Ansible? ›

Ansible® is an open source IT automation engine that automates provisioning, configuration management, application deployment, orchestration, and many other IT processes.

How do you learn Ansible automation? ›

6 Best Online Courses to learn Ansible for DevOps in 2023
  1. Ansible for the Absolute Beginner — Hands-On — DevOps. ...
  2. Mastering Ansible [Udemy] ...
  3. Mastering Ansible Automation — Step by Step. ...
  4. Ansible Advanced — Hands-On — DevOps. ...
  5. Hands-on Ansible [Pluralsight] ...
  6. Ansible: Zero to Production Ready [Educative]

Top Articles
Latest Posts
Article information

Author: Pres. Carey Rath

Last Updated:

Views: 6321

Rating: 4 / 5 (61 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Pres. Carey Rath

Birthday: 1997-03-06

Address: 14955 Ledner Trail, East Rodrickfort, NE 85127-8369

Phone: +18682428114917

Job: National Technology Representative

Hobby: Sand art, Drama, Web surfing, Cycling, Brazilian jiu-jitsu, Leather crafting, Creative writing

Introduction: My name is Pres. Carey Rath, I am a faithful, funny, vast, joyous, lively, brave, glamorous person who loves writing and wants to share my knowledge and understanding with you.