Infra Notes

Ansible first_found makes environment-specific config cleaner

Use Ansible first_found to keep host-specific, environment-specific, and default config fallback clean.

AutomationAnsibleConfig ManagementRolesAutomationMaintainability

Problem

Ansible roles become messy when every environment needs a slightly different config file.

Why it happens

Too many conditionals are added inside tasks or templates.

Fix / Approach

Use `first_found` to resolve config in priority order, such as host-specific, group-specific, then default.

Command / Config

Example lookup order:

  • `inventory_hostname.yml`
  • `group_name.yml`
  • `default.yml`

When to use

  • Agent profiles
  • Service config
  • Environment-specific files
  • Reusable roles

When not to use

  • When config must be generated dynamically from variables