AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Enhancing Ansible Role Development with Best Practices with ansible-later

By Luca Berton · Published 2024-01-01 · Category: installation

Discover ansible-later, a fast and user-friendly linting tool for Ansible roles. Learn about its installation, configuration, and default settings to enforce best practices in your Ansible codebase.

Introduction

When it comes to developing Ansible roles in a collaborative environment, adhering to coding and best practices is essential. It ensures that roles are readable, maintainable, and minimizes troubleshooting time. ansible-later is a valuable tool designed to serve as a best practice scanner and linting tool for Ansible resources.

What is ansible-later?

ansible-later focuses on providing a fast and user-friendly linting experience for Ansible roles. While it may not offer the depth of analysis provided by some other tools like ansible-lint, it serves as an excellent choice for quickly identifying and enforcing best practices within your Ansible codebase.

Installation

To get started with ansible-later, ensure that Ansible is installed on your system. You can install ansible-later using pip with one of the optional dependency groups – either ansible or ansible-core: • install for the current user • install system-wide

Configuration

By default, ansible-later ships with configurations that are suitable for most users. However, customization is possible through YAML configuration files or CLI options. The configuration options include settings for custom Ansible modules, variable formatting rules, allowed literal bools, and more.

It follows a hierarchy for configuration, with CLI options having the highest priority, allowing users flexibility in setting their preferences.

Default Settings

The default configuration includes settings for custom Ansible modules, variable formatting rules, literal bools, and more. Users can override these defaults based on their specific needs.

Usage

To lint your Ansible files, use the following command:

If no files are provided, ansible-later reviews all files in the current working directory (excluding hidden files and folders). You can also specify files, directories, or use glob patterns to target specific files for linting.

Included Rules

ansible-later comes with a set of built-in rules that cover various aspects of Ansible role development. Here are some of the rules: • LINT0001: YAML should not contain unnecessarily empty lines. • LINT0002: YAML should be correctly indented. • ANSIBLE0001: Single tasks should be separated by an empty line. • ANSIBLE0004: YAML should use a consistent number of spaces around variables. • ... and many more.

Each rule has a unique ID and description, providing developers with detailed insights into potential issues.

Links • https://ansible-later.geekdocs.de/

Example • playbook.yml • output

Conclusion

Incorporating ansible-later into your Ansible development workflow can significantly improve the quality and maintainability of your roles. By enforcing best practices and adhering to a set of rules, you contribute to a more consistent and collaborative coding environment. Remember, while ansible-later is a powerful tool, combining it with other testing and deployment tools like Molecule can further enhance your role development process.

Related ArticlesAnsible Roles Guide

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home