DEV Community

Cover image for Making Ansible Snappy, Quiet, and Friendly: A Dev’s Guide to `ansible.cfg`
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on • Edited on

Making Ansible Snappy, Quiet, and Friendly: A Dev’s Guide to `ansible.cfg`

Hello, I'm Maneshwar. I'm working on git-lrc: a Git hook for Checking AI generated code.

# Making Ansible Snappy, Quiet, and Friendly: A Dev’s Guide to ansible.cfg

Let's talk about how to optimize your Ansible playbooks using the ansible.cfg file. This file acts as a central configuration hub for Ansible, allowing you to fine-tune its behavior. Here are some key areas we'll cover:

  • Verbosity:
    Control Ansible's output level and silence unnecessary noise in your logs.

  • Networking:
    Configure network settings like default SSH ports and connection timeout values.

  • Remote Execution:
    Manage remote execution behavior, including the use of sudo or su for privileged commands.

Let's dive into specific examples to illustrate how these configurations work.

# Example: Reducing Ansible output verbosity

[defaults]
verbose = 2  
Enter fullscreen mode Exit fullscreen mode

Setting verbose to 2 reduces the amount of information displayed during playbook execution, focusing on essential messages. You can further customize verbosity levels for specific tasks or modules within your playbooks.

Why Customize?

There are several compelling reasons to tweak ansible.cfg:

  • Efficiency: Less noise in your terminal output means easier troubleshooting and faster development cycles.
  • Automation: Fine-grained control over Ansible's behavior enables more robust and automated deployments.arge infrastructures._

Ansible is great—until it floods your terminal with unreadable JSON, times out on half the hosts, and throws a hissy fit about SSH keys.

If you’re tired of that, this guide is for you.

Let’s walk through a practical ansible.cfg setup, explain what each line does, and sprinkle in some useful CLI tips.

Why ansible.cfg Even Matters

Before you start writing playbooks, tweak this config. It sets global behaviors like:

  • Inventory location
  • Logging style
  • How many hosts you run in parallel
  • Whether you want to deal with SSH key prompts ever again (spoiler: you don’t)

The Config File (ansible.cfg)

Drop this in your project root or ~/.ansible.cfg.

[defaults]
# Clean, YAML-formatted output in your terminal (no JSON dump hell)
stdout_callback = yaml
stderr_callback = yaml

# Path to your inventory file
inventory = hosts.ini

# Skip SSH key confirmation prompts
host_key_checking = False

# SSH timeout for unresponsive hosts
timeout = 30

# How many hosts to hit in parallel (default is 5)
forks = 10

# Speed up execution by skipping sudo temp file creation
pipelining = True

[ssh_connection]
# Reuse SSH sessions across tasks for faster playbook runs
pipelining = True
Enter fullscreen mode Exit fullscreen mode

Notes:

  • stdout_callback = yaml: Makes ansible-playbook output readable. No more chasing curly braces and commas.
  • pipelining = True: Reduces overhead by skipping sudo temp files and reusing SSH connections.
  • host_key_checking = False: Don’t worry, it’s fine if you’re on a controlled private infra. But maybe don’t do this in prod unless you're sure.
  • forks = 10: Increase parallelism if you're managing lots of hosts. Don’t go crazy unless your target machines and local machine can handle it.

Inventory Example (hosts.ini)

Here’s a simple static inventory format:

[web]
192.168.1.10

[db]
192.168.1.20

[master-new]
34.71.194.14 ansible_user=root
Enter fullscreen mode Exit fullscreen mode

Useful Ansible Commands

Check Host Info (with Full Debug Output)

ansible -i hosts.ini master-new -m setup -u root -vvvv
Enter fullscreen mode Exit fullscreen mode

Use this to fetch system info like IP, memory, OS, etc. -vvvv gives you full debugging output. Very handy when debugging SSH issues.

Using Roles and Collections

Generate a Role Locally

ansible-galaxy init roles/ghost --offline
Enter fullscreen mode Exit fullscreen mode

This scaffolds a new Ansible role inside roles/ghost.

Install Collections and Roles via requirements.yml

ansible-galaxy install -r requirements.yml
Enter fullscreen mode Exit fullscreen mode

Example requirements.yml:

roles:
  - src: geerlingguy.nginx
    version: 3.1.0

collections:
  - name: community.general
    version: ">=4.0.0"
Enter fullscreen mode Exit fullscreen mode

Pro Tips

  • Use --check to dry-run playbooks:
  ansible-playbook playbook.yml --check
Enter fullscreen mode Exit fullscreen mode
  • Want faster execution? Add this to your playbook:
  gather_facts: false
Enter fullscreen mode Exit fullscreen mode

Unless you need host facts, skip them to save time.

  • Combine your inventory and playbook runs:
  ansible-playbook -i hosts.ini site.yml
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

With a tuned ansible.cfg, static inventory, and solid role structure, Ansible becomes way more bearable. You’ll avoid half the pain points most devs hit when trying to automate infra.

Got a cluster to set up? Some packages to bootstrap? Use this as your launchpad and keep your ansible.cfg opinionated and tight.


With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.

Return only the cleaned text without any additional commentary:

git-lrc
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

⭐ Star it on GitHub:

GitHub logo HexmosTech / git-lrc

Free, Unlimited AI Code Reviews That Run on Commit

git-lrc logo

git-lrc

Free, Unlimited AI Code Reviews That Run on Commit


git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

See It In Action

See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements

git-lrc-intro-60s.mp4

Why

  • 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
  • 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
  • 🔁 Build a habit, ship better code. Regular review → fewer bugs → more robust code → better results in your team.
  • 🔗 Why git? Git is universal. Every editor, every IDE, every AI…




Top comments (0)