My Ansible Development Setup

A few weeks ago I started digging into the Ansible universe. One of the first things I learned was the need for a proper Ansible Development Setup. My common Ansible playbooks are focused on VMware vSphere and the ecosystem around a proper deployment workflow (IPAM, CI, DNS and so on). However, this blog post should only cover a few general topics and not specific integrations.

Ansible Control Machine

I have decided to use a simple CentOS 7 VM as Ansible Control Machine for my home lab.

Minor OS preperation and Ansible setup:

Extra packages for the VMware related Ansible Modules:

The VMware related Ansible Modules leverages for the most common functions the vSphere Management SDK packages (pyVmomi). This SDK uses the vSphere SOAP API. Some functions, such as tag management, additionally require the vSphere Automation Python SDK. This SDK uses the VMware REST API.

PowerShell for some special use cases:

Basic VIM configuration for Ansible YAML files:

The configuration file for the VIM editor is ~/.vimrc. There are also some VIM Ansible Plugins, like vim-ansible-yaml available, but for my Setup, they are net required.

My Ansible Development Setup - VIM Layout

Create Ansible Vault Password File

It is very important to protect your confidential information, especial when your projects are shared via GitHub! Ansible Vault is the tool of choice to handle sensitive data such as passwords or keys in encrypted files. At this point, we only create the password file on the Ansible Control Machine as a preparation for further steps.

Ansible Workstation

To complete the basic Ansible Development Setup, my client needs to be prepared for efficient use. I have decided to use Visual Studio Code with the Ansible Extension. The extension allows to ship the local project to the Ansible Control Machine on save and run it when needed from there.

Additional settings for the Ansible Extension:

The ansible.customOptions will ensure that my Ansible Password File will be used to encrypt the protected files with confidential data like server names, user names, passwords and other environment details.

Server file for quick access to the Workstation to Control Machine connection:

The Server File is located at “$HOME\.ssh\servers.json”.

Ansible Project

This is just a simple Ansible project with one Playbook to demonstrate the Ansible Development Setup in action.

Project folder structure:

Settings

The only Setting for the project is the Auto-Upload configuration to the Conttol Machine.

The Settings.json File is located in the .vscode folder of the Working Directory.

Variables

This project only uses the default group_vars file all.yml to store all variables. The whole file is encrypted with Ansible-Vault.

Ansible Development Setup - Ansible-Vault encrypt

With Ansible-Vault you are also able to encrypt only specific parts of a file, like a password.

Playbook

The example playbook only creates some debug messages to verify that everything works as expected.

Ansible Development Setup – Playbook Run

If all components of the Ansible Development Setup are configured properly, you are able to execute the Playbook from your local Workstation directly on the Ansible Control Machine.

Ansible Development Setup - Ansible-Playbook run

Further Info

Share with:

2 Comments

  1. Dan 22. March 2019
    • Markus Kraus 22. March 2019

Leave a Reply