Ansible-lint for playbooks

Feb 22, 2015 • Jonathan Frappier

During the #vBrownBag DevOps series after-show from my Using Ansible to provision VM’s in vCenter, Mike Marseglia asked about options for linting Ansible playbooks. Since I didn’t know, I thought it would be worthwhile to look into it. There is an Ansible-Lint repo on GitHub, reading through the information, it seemed straight forward. Here I am going to have a look at installing and using it against some example playbooks.

Installation should be easy, assuming you’ve got the correct packages installed, see my previous Ansible posts - if you got through that install, you should be able to install this with a single line:

pip install ansible-lint

Once installed you should now be able to do something like this:

ansible-lint clone-vm.yml

The clone-vm.yml is from my #vBrownBag series. As you can see in this screenshot, it suggests I have some trailing whitespace

Once I tiddy up the extra whitespace in the playbook, no suggestions are returned.

That is a pretty basic example, let’s say I’ve missed something such as a { when using vars_prompt, here you can see I have a missing backet for vm

Once again, now that it is fixed, no suggestions are returned. One thing that at least this specific tool does not help with is spacing errors, so your playbook will need to be valid, running ansible-lint here for example where my spacing is incorrect results in an general Ansible error, though it does point out where the error likely is:

Going forward I’ll certainly be looking into using this when writing a playbook to ensure general recommended practices are adhereed to. I’m still on the lookout for a tool that can help with spacing though!

Scenario: You try to install the VMware vCenter Server Appliance (VCSA) or Platform Services Controller but receive an error during the installation. After correcting the problem during installation you attempt to re-install the appliance but receive the following error message:

I wanted to share some of the example Ansible playbooks used during last Wednesday’s US #vBrownBag. During the show I went over examples of how you can use Ansible to create, clone, and update virtual machines in vCenter without the need for other provisioning tools. Based on my testing (and I’m still learning as well), the items noted in the comments are the bare minimum needed to run the playbook, even though the official documentation may currently state otherwise. If you are already using Ansible for configuration management, this is a handy option to have as you can perform the provisioning tasks without leaving Ansible.