How do i run Ansible playbook from Jenkins job?Rajeev Sharma2025-03-24T16:51:47+05:30Method 1: Using the “Ansible” Plugin
- In Jenkins, create a Freestyle Project.
- Under Build Steps, select Invoke Ansible Playbook.
- Provide the playbook path (
/path/to/playbook.yml
). - Add any extra parameters (e.g.,
-i inventory.ini
).
Method 2: Using a Shell Command
- Create a Freestyle Project.
- Add a Build Step → Execute Shell and run:
ansible-playbook -i inventory.ini playbook.yml
Method 3: Using a Jenkins Pipeline Script
pipeline {
agent any
stages {
stage('Run Ansible') {
steps {
sh 'ansible-playbook -i inventory.ini playbook.yml'
}
}
}
}