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.
More on Architecture Decisions and Tool Comparisons
Ansible or Terraform: where do you draw the line?BeginnerHow does Ansible compare with Puppet, Chef and Salt?IntermediateWhy use Ansible instead of shell scripts?BeginnerWhere does Ansible fit once you run Kubernetes?IntermediateWhen would you use AWS Systems Manager instead of, or together with, Ansible?IntermediateShould Ansible do application deployments or should a CD tool?Advanced