Most Ansible pain is self-inflicted and predictable. Here are the mistakes we see most, and the fix for each.
Mistake 1: Non-idempotent shell/command tasks that run every time regardless of state
Fix: Prefer modules over raw shell; add changed_when/creates to shell tasks. Make it the default in your templates and enforce it in review or CI so the mistake cannot come back.
Mistake 2: Secrets in plaintext instead of Ansible Vault
Fix: Structure logic into roles and use group_vars/host_vars. Make it the default in your templates and enforce it in review or CI so the mistake cannot come back.
Mistake 3: Giant single playbooks instead of reusable roles
Fix: Encrypt secrets with Ansible Vault and keep the key out of the repo. Make it the default in your templates and enforce it in review or CI so the mistake cannot come back.
A safer baseline
A playbook that installs and enables nginx idempotently.
- 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 }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.