From Ad-Hoc to a Repeatable Playbook
Turn commands into a saved YAML file.
From Ad-Hoc to a Repeatable Playbook is a free Ansible Academy lesson on CoddyKit — lesson 2 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.
Ad-Hoc Commands Vanish
An ad-hoc command runs once and is gone. It is great for quick checks, but it leaves no record of what you did.
ansible web -m service -a "name=nginx state=started"A Playbook Is Saved Work
A playbook writes that same intent into a YAML file. You commit it, share it, and run it again whenever you need.
One Command Maps to One Task
Each ad-hoc command becomes a single task in the playbook. The module and its arguments carry straight over.
- name: start nginx
service:
name: nginx
state: startedA Play Wraps Your Tasks
Tasks live inside a play. The play says which hosts to target, then lists the tasks to run on them.
- hosts: web
tasks:
- name: start nginx
service:
name: nginx
state: startedThe hosts Line
The hosts key replaces the host pattern you typed on the command line. It picks the group the play will manage.
- hosts: webModule Args Become Keys
The key=value arguments from your command turn into indented YAML keys under the module name. Same data, clearer shape.
service:
name: nginx
state: startedRepeatable Means Reliable
Because the file never changes, every run does exactly the same thing. This repeatability is what makes automation trustworthy.
Self-Documenting Automation
A playbook also documents your infrastructure. Reading the file tells the next person exactly how the server should be configured.
Add a Second Task Easily
Growing the file is simple: add another dash under tasks. Ad-hoc forces a new command, but a playbook just keeps the list.
tasks:
- name: start nginx
service:
name: nginx
state: started
- name: open firewall
debug:
msg: doneVersion Control It
Save the playbook in Git like any code. Now your server config has history, review, and the ability to roll back changes.
Name the File .yml
By convention a playbook file ends in .yml or .yaml. The name is up to you, like site.yml or webservers.yml.
Quick Check
Why move a working ad-hoc command into a playbook?
From One-Off to Forever
You turned a throwaway command into a saved playbook: a host, a task, and a repeatable record of how your server runs. 🚀
Frequently asked questions
Is the “From Ad-Hoc to a Repeatable Playbook” lesson free?
Yes — the full text of “From Ad-Hoc to a Repeatable Playbook” 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 “From Ad-Hoc to a Repeatable Playbook”?
Turn commands into a saved YAML file. 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 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “From Ad-Hoc to a Repeatable Playbook” 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
- YAML Syntax You Need for Ansible
- From Ad-Hoc to a Repeatable Playbook
- Run It with ansible-playbook
- Install Nginx in Five Lines