Interview Prep/Ansible/Architecture Decisions and Tool Comparisons

cloud-init or Ansible for first boot configuration?

IntermediateProductionArchitecture Decisions and Tool Comparisons
Answer

They work best together. cloud-init runs inside the instance at first boot with no network dependency on a controller, so it is ideal for the minimum: hostname, users and keys, mounting disks, installing the agent or Python, and registering the instance.

Ansible then does the real configuration, either pushed from AWX/CI once the instance is reachable, or via ansible-pull triggered from cloud-init.

#cloud-config
users:
  - name: ansible
    ssh_authorized_keys: ["ssh-ed25519 AAAA... ansible@ctl"]
    sudo: "ALL=(ALL) NOPASSWD:ALL"
packages: [python3]

Do not let cloud-init grow into a second configuration management system; logic in user data is hard to test, version and re-run.

All Ansible questions Roadmap: Ansible

More on Architecture Decisions and Tool Comparisons