← All insightsAutomation

Automating Ansible from scratch

CodeWizard Academy · 4 August 2026 · 3 min read · Intermediate

Anything you do to Ansible twice should be automated. This walks the path from a manual install to a repeatable, pipeline-driven setup.

1. Install it reproducibly

bash
python3 -m pip install --user ansible
ansible --version
ansible all -i inventory.ini -m ping

2. Describe the desired state

A playbook that installs and enables nginx idempotently.

yaml
- hosts: web
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.package:
        name: nginx
        state: present
    - name: Ensure nginx is running and enabled
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true
    - name: Deploy site config
      ansible.builtin.template:
        src: site.conf.j2
        dest: /etc/nginx/conf.d/site.conf
      notify: reload nginx
  handlers:
    - name: reload nginx
      ansible.builtin.service: { name: nginx, state: reloaded }

3. Run it from CI

Lint playbooks and run in check mode in CI.

yaml
- run: ansible-lint
- run: ansible-playbook -i inventory.ini site.yml --check --diff

Want senior help putting Ansible to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult