Ansible and cloud-init orientation
Quick answer
Ansible organizes configuration tasks against inventory targets; cloud-init commonly prepares a new instance from supplied user-data. They address related but distinct stages.
Use provisioning to establish a known starting point and configuration management to maintain it over time. Do not assume every task or cloud-init stage reruns on each boot. Verify the tool's actual execution scope and the resulting state on a disposable instance.
Prepare the practice environment
Run python3 lab-fixtures/automation/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not modify system services. Review the lab guide.
Prerequisites
Review: Configuration validation and rollback.
How it works
Inventory defines hosts and groups. A playbook connects selected hosts to ordered tasks; purpose-built modules can compare desired and actual state, but arbitrary commands are not automatically idempotent. Check mode is a preview only where supported, and diff output can expose confidential data. Begin with a local inventory and no privilege escalation. cloud-init runs initialization modules according to boot stages and module frequency; not every module runs only once. A cloud-config document begins with #cloud-config, and schema validation does not execute its instructions or prove a successful boot. The supplied playbook and user-data are intentionally harmless orientation fixtures. No cloud instance is needed.
Try the examples
The group contains only localhost, with a local connection instead of SSH.
Expected stdout:
[lab]localhost ansible_connection=localansible lab -i inventory.ini --list-hostsOptional: on a disposable VM with Ansible installed, expect localhost as the sole selected host. No modules are executed. Inspect playbook.yml separately.
Manual example; not executed locally. Follow its stated environment restrictions.
cloud-init schema --config-file cloud-config.yamlOptional: use a VM with a version supporting this CLI. The document should validate; do not run cloud-init stages or modify an instance.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not run a playbook against all production hosts as a first test. Never place passwords in example user-data or blindly rely on check mode.
Practice
Inspect inventory.ini, playbook.yml and cloud-config.yaml. Explain which tools select targets, which initialize instances, and why schema validation is not a boot test.
Related references
Study: ansible, cloud-init. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Ansible and cloud-init orientation — Knowledge Check
Apply configuration management concepts to synthetic fixtures and VM-only scenarios.
What does inventory define?
What is check mode?
What is cloud-init commonly used for?
Does schema validation execute user-data?