Provision Then Configure in One Flow
Hand off new hosts to config plays.
Provision Then Configure in One Flow is a free Ansible Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Two Jobs, One Playbook
Provisioning makes a server exist. Configuring makes it useful. The real power is doing both in a single, smooth play. 🔗
Provision on the Control Node
Cloud creation tasks run locally against the AWS API, so the provisioning play targets localhost, not the new server.
- hosts: localhost
gather_facts: false
tasks:
- amazon.aws.ec2_instance: { name: web-01 }Capture the New Host
You cannot SSH to a box you do not know about yet. register the ec2_instance result to grab its fresh public IP.
- amazon.aws.ec2_instance:
name: web-01
register: ec2Add It to Inventory in Memory
The add_host module injects the new server into the running inventory, so a later play can target it without a static file.
- add_host:
name: "{{ ec2.instances[0].public_ip_address }}"
groups: launchedWait Until SSH Is Ready
A booting instance is not instantly reachable. wait_for pauses until port 22 answers before you try to connect.
- wait_for:
host: "{{ ec2.instances[0].public_ip_address }}"
port: 22Start a Second Play
Now open a new play that targets the launched group you just built. This play runs on the cloud server itself.
- hosts: launched
become: true
tasks:
- ping:Configure the Fresh Host
With the host in inventory, ordinary modules take over. Install packages, copy configs, and start services exactly as on any node.
- hosts: launched
tasks:
- package:
name: nginx
state: presentPass the Right SSH User
Cloud images use specific logins, like ubuntu or ec2-user. Set ansible_user so the config play connects correctly.
add_host:
name: "{{ ec2.instances[0].public_ip_address }}"
groups: launched
ansible_user: ubuntuOne File, End to End
The result is a single playbook: play one creates infrastructure, play two configures it. Run it once and a working server appears.
Idempotent All the Way
Both halves are idempotent. Re-running matches the existing instance and converges the config, so the flow is safe to repeat.
Skip Host Key Prompts
A brand-new host has an unknown SSH key. Set host_key_checking off for the launched group so the first connection does not stall.
add_host:
name: "{{ ec2.instances[0].public_ip_address }}"
groups: launched
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"Quick Check
You just launched an EC2 box and want the next play to configure it, with no static inventory entry. What bridges the gap?
Recap
You linked provision and configure: create on localhost, register the IP, add_host, wait for SSH, then configure in a second play. ✨
Frequently asked questions
Is the “Provision Then Configure in One Flow” lesson free?
Yes — the full text of “Provision Then Configure in One Flow” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.
What will I learn in “Provision Then Configure in One Flow”?
Hand off new hosts to config plays. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Ansible Academy?
No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Provision Then Configure in One Flow” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Ansible Academy lesson?
Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Cloud Collections & Authentication
- Launch EC2 Instances Declaratively
- Networking: VPCs, Subnets & Security Groups
- Provision Then Configure in One Flow