AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Ansible vs Jenkins: When to Use Each and How to Combine Them (2026 Guide)

By Luca Berton · Published 2024-01-01 · Category: installation

Ansible vs Jenkins comparison for automation and CI/CD. Key differences, use cases, and how to integrate Ansible with Jenkins pipelines.

Ansible vs Jenkins: When to Use Each and How to Combine Them (2026 Guide)

Ansible and Jenkins solve different problems. Jenkins orchestrates CI/CD pipelines — building, testing, and deploying code. Ansible automates infrastructure — configuring servers, deploying applications, and managing state. Most teams use both together.

See also: AAP 2.6 CI/CD Pipeline Integration: GitOps Workflows with Jenkins, GitLab, and GitHub Actions

Key Differences

Ansible:

  • Configuration management and infrastructure automation
  • Agentless (SSH-based)
  • Declarative YAML playbooks
  • Idempotent (safe to re-run)
  • Push-based execution
  • Infrastructure as Code
Jenkins:
  • CI/CD pipeline orchestration
  • Server-based with agents/workers
  • Groovy Jenkinsfiles or GUI pipelines
  • Procedural (step-by-step)
  • Event-driven (triggers on code push, schedule, webhook)
  • Build/test/deploy workflows

When to Use Each

TaskAnsibleJenkins
Install packages on servers
Configure nginx/Apache
Build Java/Python/Node app
Run unit/integration tests
Deploy app to servers✅ (triggers Ansible)
Manage Docker containers
Provision cloud infrastructure
Trigger on git push
Enforce server compliance
Create CI/CD dashboards

Using Ansible with Jenkins

The most powerful pattern: Jenkins orchestrates the pipeline, Ansible handles the infrastructure.

Jenkins Pipeline Calling Ansible

// Jenkinsfile
pipeline {
    agent any
    
    environment {
        ANSIBLE_HOST_KEY_CHECKING = 'False'
    }
    
    stages {
        stage('Build') {
            steps {
                sh 'npm install && npm run build'
            }
        }
        
        stage('Test') {
            steps {
                sh 'npm test'
            }
        }
        
        stage('Deploy to Staging') {
            steps {
                ansiblePlaybook(
                    playbook: 'deploy.yml',
                    inventory: 'inventory/staging.ini',
                    credentialsId: 'ansible-ssh-key',
                    extras: "-e app_version=${BUILD_NUMBER}"
                )
            }
        }
        
        stage('Deploy to Production') {
            when {
                branch 'main'
            }
            input {
                message "Deploy to production?"
            }
            steps {
                ansiblePlaybook(
                    playbook: 'deploy.yml',
                    inventory: 'inventory/production.ini',
                    credentialsId: 'ansible-ssh-key',
                    extras: "-e app_version=${BUILD_NUMBER}"
                )
            }
        }
    }
}

Jenkins Ansible Plugin

Install the Ansible plugin in Jenkins to get the ansiblePlaybook step:

// With the Ansible plugin
ansiblePlaybook(
    playbook: 'site.yml',
    inventory: 'inventory/hosts',
    credentialsId: 'ssh-key-id',
    colorized: true,
    extras: '-e "env=production" --tags deploy'
)

Shell-Based Integration

// Without the Ansible plugin
stage('Deploy') {
    steps {
        withCredentials([sshUserPrivateKey(
            credentialsId: 'ansible-key',
            keyFileVariable: 'SSH_KEY'
        )]) {
            sh """
                ansible-playbook deploy.yml \
                    -i inventory/production.ini \
                    --private-key=${SSH_KEY} \
                    -e "version=${BUILD_NUMBER}" \
                    -e "deployed_by=jenkins"
            """
        }
    }
}

Ansible Deploy Playbook Example

---
# deploy.yml — called by Jenkins
- name: Deploy application
  hosts: webservers
  become: true
  vars:
    app_version: "{{ version | default('latest') }}"
    app_dir: /opt/myapp
    deploy_user: deploy

  tasks:
    - name: Download release artifact
      ansible.builtin.get_url:
        url: "https://artifacts.example.com/myapp-{{ app_version }}.tar.gz"
        dest: "/tmp/myapp-{{ app_version }}.tar.gz"

    - name: Create release directory
      ansible.builtin.file:
        path: "{{ app_dir }}/releases/{{ app_version }}"
        state: directory
        owner: "{{ deploy_user }}"

    - name: Extract release
      ansible.builtin.unarchive:
        src: "/tmp/myapp-{{ app_version }}.tar.gz"
        dest: "{{ app_dir }}/releases/{{ app_version }}"
        remote_src: true

    - name: Update symlink
      ansible.builtin.file:
        src: "{{ app_dir }}/releases/{{ app_version }}"
        dest: "{{ app_dir }}/current"
        state: link
      notify: restart app

  handlers:
    - name: restart app
      ansible.builtin.systemd:
        name: myapp
        state: restarted

See also: Ansible vs GitHub Actions: Key Differences & When to Use Each (2026)

Ansible vs Jenkins vs Other Tools

ToolPrimary UseApproach
AnsibleConfig management, deploymentAgentless, push, YAML
JenkinsCI/CD pipelinesServer + agents, Groovy
GitHub ActionsCI/CD (GitHub-native)YAML workflows
TerraformInfrastructure provisioningDeclarative HCL
Puppet/ChefConfig managementAgent-based, pull
ArgoCDKubernetes GitOpsDeclarative, pull

FAQ

Can Ansible replace Jenkins?

No. Ansible is not a CI/CD server — it doesn't watch repositories, run tests, or build artifacts. Jenkins orchestrates pipelines with triggers, parallel stages, and dashboards. They complement each other: Jenkins for CI/CD, Ansible for infrastructure.

Can Jenkins replace Ansible?

Partially. Jenkins can run shell commands on remote servers, but it lacks Ansible's idempotency, inventory management, and hundreds of modules for infrastructure automation. Using Ansible through Jenkins is better than scripting deployments manually.

How do I call Ansible from Jenkins?

Install the Jenkins Ansible plugin and use ansiblePlaybook() in your Jenkinsfile. Alternatively, run ansible-playbook as a shell command. Pass Jenkins variables to Ansible with -e.

Is Ansible better than Jenkins for deployments?

Ansible is better at the deployment itself (copying files, configuring services, managing state). Jenkins is better at orchestrating when and how deployments happen (after tests pass, with approvals, on schedule). Use both together.

What is the Jenkins Ansible plugin?

The Jenkins Ansible plugin provides the ansiblePlaybook pipeline step for calling Ansible playbooks directly from Jenkinsfiles. It integrates with Jenkins credentials for SSH keys and vault passwords.

Conclusion

Ansible and Jenkins are complementary tools. Jenkins orchestrates your CI/CD pipeline — build, test, approve. Ansible handles what happens on servers — configure, deploy, enforce state. Together they form a complete automation stack.

See also: Ansible vs Jenkins: Key Differences and When to Use Each

Category: installation

Browse all Ansible tutorials · AnsiblePilot Home