Skip to main content
๐ŸŽ“ Claude Code Masterclass Learn AI-assisted development on Udemy โ€” plus the companion book on Leanpub & Amazon. Start Learning
How to Install Ansible on GitHub Actions
Automation

How to Install Ansible on GitHub Actions

Step-by-step guide to install Ansible on GitHub Actions. Covers package installation, pip install, version management, and first playbook setup.

LB
Luca Berton
ยท 1 min read

Here is how to use Ansible in GitHub Actions CI/CD pipelines in 2026.

Basic Workflow

name: Ansible Deploy
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Ansible
        run: sudo apt-get update && sudo apt-get install -y ansible
      - name: Install collections
        run: ansible-galaxy collection install -r requirements.yml
      - name: Run playbook
        run: ansible-playbook -i inventory playbook.yml
        env:
          ANSIBLE_HOST_KEY_CHECKING: "false"

With SSH Key

      - name: Setup SSH
        run: |
          mkdir -p ~/.ssh
          echo "$SSH_KEY" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
        env:
          SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}

With Ansible Vault

      - name: Run with vault
        run: ansible-playbook -i inventory playbook.yml --vault-password-file <(echo "$VAULT_PASS")
        env:
          VAULT_PASS: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}

Lint Only

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pip install ansible-lint
      - run: ansible-lint playbook.yml

Free 30-min AI & Cloud consultation

Book Now