Skip to content

Ansible Variables

Variables help you keep playbooks flexible instead of hardcoding values for every host.

Group Variables

Use group variables when the same value applies to many hosts.

http_port: 80
ntp_servers:
  - 0.pool.ntp.org
  - 1.pool.ntp.org

Host Variables

Use host variables only when one server needs different values.

http_port: 8080

Practical Advice

  • Put shared values in group variables first
  • Keep host variables small and specific
  • Use clear names that match the service or purpose

Quick Check

ansible-inventory -i inventory.ini --host myserver