How do i run Ansible playbook from Jenkins job?

Method 1: Using the “Ansible” Plugin

  1. In Jenkins, create a Freestyle Project.
  2. Under Build Steps, select Invoke Ansible Playbook.
  3. Provide the playbook path (/path/to/playbook.yml).
  4. Add any extra parameters (e.g., -i inventory.ini).

Method 2: Using a Shell Command

  1. Create a Freestyle Project.
  2. 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'
            }
        }
    }
}