AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 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 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", 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.

How to install ansible-lint in macOS

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

How to install the ansible-lint command line utility and use it to improve our Ansible Playbooks in macOS Intel and Silicon.

How to install ansible-lint in macOS

What is the ansible-lint tool?

> ansible-lint checks playbooks for practices and behavior that could potentially be improved.

Ansible-Lint is a command-line tool for linting playbooks, roles, and collections aimed toward any Ansible users. Its main goal is to promote proven practices, patterns, and behaviors while avoiding common pitfalls that can easily lead to bugs or make code harder to maintain.

See also: Installing JetPorch via Packages on macOS

Links

• ansible-lint https://ansible-lint.readthedocs.io/ • Homebrew https://brew.sh/

Installation in macOS

Let's install the ansible-lint tool in macOS using the Homebrew package manager. I suppose the Homebrew is already installed using the Homebrew https://brew.sh/ website. The brew tool works on macOS Intel and Silicon (M1, M2, M1Pro, M2Pro, M1Max, M2Max, M1Ultra, M2Ultra).

before

% ansible-lint
zsh: command not found: ansible-lint
% brew search ansible-lint
==> Formulae
ansible-lint                                 ansible ✔

==> Casks ansible-dk

installation command

The installation command downloads the required files and dependencies (sqlite, ansible, black, pygments and yamllint) and install them in our system.

% brew install ansible-lint

execution

% brew install ansible-lint
==> Fetching dependencies for ansible-lint: sqlite, ansible, black, pygments and yamllint
==> Fetching sqlite
==> Downloading https://ghcr.io/v2/homebrew/core/sqlite/manifests/3.41.0
Already downloaded: /Users/lberton/Library/Caches/Homebrew/downloads/19202efbc509ad22113d571d4b2aaa86fdbf2e3c5299fde49c6a0bb41d9b0328--sqlite-3.41.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/sqlite/blobs/sha256:72073c161c9ee425437a
Already downloaded: /Users/lberton/Library/Caches/Homebrew/downloads/c1511ff7e302362a8736c0964fb633597bee677c78599790eb905eb3e5ff27f4--sqlite--3.41.0.arm64_ventura.bottle.tar.gz
==> Fetching ansible
==> Downloading https://ghcr.io/v2/homebrew/core/ansible/manifests/7.3.0
Already downloaded: /Users/lberton/Library/Caches/Homebrew/downloads/8abde3dff30d5f40dee39f30248a558f50232653b325325b924a206bf6cfb3ad--ansible-7.3.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/ansible/blobs/sha256:11869f8ad5ad1d3ba34
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:1186
######################################################################## 100.0%
==> Fetching black
==> Downloading https://ghcr.io/v2/homebrew/core/black/manifests/23.1.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/black/blobs/sha256:ae6062bf90830375e496d
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:ae60
######################################################################## 100.0%
==> Fetching pygments
==> Downloading https://ghcr.io/v2/homebrew/core/pygments/manifests/2.14.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/pygments/blobs/sha256:d4b2214521e36150b2
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:d4b2
######################################################################## 100.0%
==> Fetching yamllint
==> Downloading https://ghcr.io/v2/homebrew/core/yamllint/manifests/1.29.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/yamllint/blobs/sha256:27ce7abb1de9cd41d6
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:27ce
######################################################################## 100.0%
==> Fetching ansible-lint
==> Downloading https://ghcr.io/v2/homebrew/core/ansible-lint/manifests/6.14.0
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ansible-lint/blobs/sha256:df267ef8de202e
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:df26
######################################################################## 100.0%
==> Installing dependencies for ansible-lint: sqlite, ansible, black, pygments and yamllint
==> Installing ansible-lint dependency: sqlite
==> Pouring sqlite--3.41.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/sqlite/3.41.0: 11 files, 4.5MB
==> Installing ansible-lint dependency: ansible
==> Pouring ansible--7.3.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/ansible/7.3.0: 29,252 files, 378.6MB
==> Installing ansible-lint dependency: black
==> Pouring black--23.1.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/black/23.1.0: 1,124 files, 13.9MB
==> Installing ansible-lint dependency: pygments
==> Pouring pygments--2.14.0.all.bottle.tar.gz
🍺  /opt/homebrew/Cellar/pygments/2.14.0: 624 files, 8.1MB
==> Installing ansible-lint dependency: yamllint
==> Pouring yamllint--1.29.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/yamllint/1.29.0: 821 files, 10.6MB
==> Installing ansible-lint
==> Pouring ansible-lint--6.14.0.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/ansible-lint/6.14.0: 1,351 files, 14.2MB
% brew search ansible-lint
==> Formulae
ansible-lint ✔                               ansible ✔

==> Casks ansible-dk

verification

% ansible-lint --version
ansible-lint 6.14.0 using ansible 2.14.3

See also: Automate Redmine Installation on Ubuntu LTS 22.04 with Ansible

Conclusion

Now you know how to install the ansible-lint command line utility in macOS.

Related Articles

Ansible Roles Guide

See also: Improve Playbook Debugging Using Ansible Lint

Configuration

Create an .ansible-lint configuration file in your project:

# .ansible-lint
skip_list:
  - yaml[line-length]  # Allow long lines
  - name[casing]       # Allow flexible task naming

warn_list: - no-changed-when # Warn instead of fail

use_default_rules: true offline: false

# Exclude paths exclude_paths: - .github/ - molecule/ - tests/

Common ansible-lint Rules

| Rule | Description | Severity | |---|---|---| | yaml[truthy] | Use true/false not yes/no | Warning | | no-changed-when | Commands need changed_when | Warning | | name[missing] | Tasks should have names | Error | | fqcn[action-core] | Use FQCN for builtin modules | Warning | | risky-shell-pipe | Shell pipes need pipefail | Error |

Running ansible-lint

# Lint a specific playbook
ansible-lint playbook.yml

# Lint all YAML files in current directory ansible-lint

# Auto-fix issues (where possible) ansible-lint --fix

# Show only specific severity ansible-lint -p # Parseable output for CI

FAQ

What is the difference between ansible-lint and yamllint?

yamllint checks YAML syntax only. ansible-lint understands Ansible semantics — it checks for best practices, deprecated modules, missing FQCN, and Ansible-specific patterns.

How do I integrate ansible-lint with VS Code?

Install the "Ansible" extension by Red Hat. It includes ansible-lint integration and highlights issues directly in the editor.

Can I run ansible-lint in CI/CD?

Yes. Add it to your CI pipeline:

pip install ansible-lint
ansible-lint --strict  # Non-zero exit on warnings

Category: installation

Watch the video: How to install ansible-lint in macOS — Video Tutorial

Browse all Ansible tutorials · AnsiblePilot Home