Infrastructure as code is an approach to managing servers where their configuration is defined using code and version control rather than manual shell commands. Ansible is a tool that allows defining servers' desired state in YAML files checked into version control. It can automatically install software, configure systems, and ensure consistency across multiple servers using SSH without requiring an agent. Playbooks declare tasks to run that are idempotent, allowing Ansible to safely deploy changes. This approach improves on manual configuration by enabling testing, collaboration, and rolling back changes if needed.