Infrastructure as Code & Automation
Describing servers, networks and their configuration in files and letting tools build and maintain them: Terraform and OpenTofu for provisioning, Ansible for configuration, and the practices around them, from state and secrets to testing, pipelines and troubleshooting.
18 pages 134 glossary terms Terraform Associate Linux+
How to use this topic
This topic goes deeper than the overview page on infrastructure as code in the Cloud topic. The first two pages explain the idea and the file formats. Pages 3 to 8 are about Terraform and OpenTofu: a first configuration, variables, state, modules, changing infrastructure safely and running several environments. Pages 9 to 12 are about Ansible: inventories, playbooks, variables and templates, roles and collections. The last six cover secrets, other tools, machine images, testing, pipelines and troubleshooting.
The OpenTofu and Ansible output on these pages was recorded with
real runs on a test machine, using only providers that create local
files and random values, and Ansible hosts that point at that same
machine. Output that needs a real cloud account, real servers or
tools that were not installed is marked illustrative. Every
configuration block is checked: HCL with tofu fmt and
YAML with a YAML parser.
Pages are tagged with the certifications they help with: Terraform Associate (HashiCorp Certified: Terraform Associate) on the Terraform pages — the exam is about Terraform, but those pages apply to OpenTofu as well — and CompTIA Linux+ on the pages about Ansible, OpenTofu basics, cloud-init and pipelines, which its automation objective names.
Learning path
- 01What Is Infrastructure as Code?Why infrastructure is described in files instead of built by hand: declarative and imperative approaches, idempotency, drift, mutable and immutable infrastructure, and the main tool families.
- 02Configuration Languages: HCL, YAML and JSONThe file formats infrastructure tools are written in: HCL blocks and expressions, YAML and its pitfalls, JSON, and templating, with the same setting shown in each.
- 03Terraform and OpenTofu: First StepsWriting and applying a first configuration: providers and resources, the init, plan and apply cycle, the lock file, destroying what you made, and how Terraform and OpenTofu differ.
- 04Variables, Outputs and ExpressionsMaking configurations flexible: input variables with types and validation, locals, outputs, data sources, count and for_each, and the built-in functions.
- 05State: How Terraform RemembersWhat the state file holds and why it matters: remote backends, locking, sensitive values in state, state encryption in OpenTofu, and the state commands you need when things go wrong.
- 06Modules and ReusePackaging configuration into modules: inputs and outputs, local and registry modules, versioning and pinning, and how to keep modules small and useful.
- 07Changing Infrastructure SafelyReading a plan before you apply it: create, update and replace, drift and refresh, importing existing resources, moved blocks, lifecycle rules and preventing accidental destruction.
- 08Environments: Dev, Test and ProductionRunning the same infrastructure in several environments: separate directories, workspaces, variable files, separate state and credentials, and keeping environments alike.
- 09Ansible BasicsConfiguration management without agents: the control node, inventories and groups, ad-hoc commands, modules, SSH connections and privilege escalation.
- 10Playbooks and IdempotencyWriting playbooks: plays and tasks, changed and ok, handlers, check and diff mode, conditionals, loops, and why a good playbook can run twice without harm.
- 11Variables, Facts and TemplatesWhere Ansible values come from: group_vars and host_vars, variable precedence, gathered facts, registered results, and generating configuration files with Jinja2 templates.
- 12Roles and CollectionsStructuring Ansible work: the role layout, defaults and handlers in roles, collections and fully qualified names, Ansible Galaxy, and pinning what you install.
- 13Secrets in AutomationKeeping passwords and keys out of code: Ansible Vault, SOPS, secret managers such as HashiCorp Vault and OpenBao, sensitive values in Terraform, and short-lived credentials with OIDC.
- 14Other Infrastructure as Code ToolsThe wider landscape: CloudFormation, Bicep, Pulumi and the CDK, Crossplane, Puppet, Chef and Salt, PowerShell DSC, and how to choose.
- 15Images and BootstrappingGetting a new machine ready: golden images built with Packer, cloud-init and user data, configuration at boot versus baked into the image, and immutable servers.
- 16Testing and Policy as CodeCatching mistakes before they reach production: formatting and validation, linters such as TFLint and ansible-lint, the test command, Molecule, security scanners, and policy as code with OPA.
- 17Infrastructure as Code in PipelinesRunning infrastructure changes through CI/CD: plan on every pull request, review and approval, apply from the pipeline, drift detection, and least-privilege credentials.
- 18Troubleshooting Infrastructure as CodeFinding and fixing common failures: provider and version errors, a stuck state lock, unexpected replacements, Ansible connection and privilege errors, debug output and safe recovery.
Infrastructure as Code & Automation glossary
Short definitions of the terms used in this topic. The full glossary covers every topic.