Run Playbooks in GitHub Actions
Trigger automation from commits.
Run Playbooks in GitHub Actions 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.
CI Runs Your Automation
With GitHub Actions, every push can run your playbooks on a fresh runner, so automation is tested the same way every time. 🚀
Workflows Live in .github
A workflow is a YAML file under .github/workflows; GitHub finds it there and runs it automatically.
.github/workflows/ansible.ymlTrigger on Push
The on key decides when a workflow runs. Triggering on push to main is the classic CI starting point.
on:
push:
branches: [ main ]A Job on a Runner
Each job runs on a virtual machine you pick with runs-on, most often a clean ubuntu-latest image.
jobs:
deploy:
runs-on: ubuntu-latestCheck Out Your Code
The first step is almost always actions/checkout, which copies your repo onto the runner so playbooks are present.
- uses: actions/checkout@v4Install Ansible on the Runner
The runner is bare, so add a step to install Ansible with pip before you can call any playbook.
- run: pip install ansibleLint Before You Run
Add an ansible-lint step early; if it fails, the job stops and the deploy step never even starts.
- run: |
pip install ansible-lint
ansible-lintCall ansible-playbook
The payoff step runs ansible-playbook just like your terminal would, pointing at your inventory and file.
- run: ansible-playbook -i inventory site.ymlSecrets, Not Hardcoded Keys
Never paste credentials in the YAML. Read them from GitHub Secrets through the secrets context instead.
env:
SSH_KEY: ${{ secrets.SSH_KEY }}Reach Hosts Over SSH
To touch real servers the runner needs the SSH key loaded into its agent, fed in from a secret you stored earlier.
Read the Live Logs
The Actions tab streams every step's output, so a failed task shows up exactly where Ansible reported it.
Quick Check
Where does a GitHub Actions workflow file belong?
Recap: Pushes Now Deploy
You built a workflow: trigger on push, check out, install Ansible, lint, then run the playbook with secrets. CI does the work now. 🎉
Frequently asked questions
Is the “Run Playbooks in GitHub Actions” lesson free?
Yes — the full text of “Run Playbooks in GitHub Actions” 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 “Run Playbooks in GitHub Actions”?
Trigger automation from commits. 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 “Run Playbooks in GitHub Actions” 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
- ansible-lint as a Quality Gate
- Run Playbooks in GitHub Actions
- Vault Secrets in a Pipeline
- Gated Deploys with Approvals & Check Mode