| name | task-ordering |
| description | Task dependency ordering for Ansible playbooks, ensuring prerequisites are met before dependent operations. Includes system state, package, configuration, and service ordering. |
Task Ordering — Dependencies First
Use when writing Ansible task files, playbook ordering, or project plans. Dependencies must be resolved top-down before implementation tasks.
Rules
- ALWAYS fix system state before package installation (repair broken apt first)
- NEVER use package commands before installing the package (install
wireguard-tools before wg genkey)
- NEVER configure services before generating keys/credentials
- NEVER start services before writing configuration files
- NEVER verify runtime state before starting services
- NEVER start dependent services before network configuration
- NEVER use kernel modules before loading them on host
- ALWAYS run shared infrastructure before service provisioning
Patterns
Correct dependency order:
- name: Fix broken dpkg packages
ansible.builtin.command: dpkg --configure -a
- name: Install wireguard tools
ansible.builtin.apt:
name: wireguard-tools
- name: Generate WireGuard keypair
ansible.builtin.command: wg genkey
register: wg_private_key
- name: Write WireGuard config
ansible.builtin.template:
src: wg0.conf.j2
dest: /etc/wireguard/wg0.conf
- name: Enable and start WireGuard
ansible.builtin.systemd:
name: wg-quick@wg0
state: started
enabled: true
- name: Verify WireGuard interface
ansible.builtin.command: wg show wg0
Site.yml play ordering:
- hosts: proxmox
roles:
- proxmox_bridges
- proxmox_pci_passthrough
- proxmox_igpu
- hosts: flavor_group
roles:
- service_vm
- deploy_stamp
- hosts: dynamic_group
roles:
- service_configure
Anti-patterns
NEVER explain what dependencies are in task ordering rules
NEVER install packages after trying to use them
NEVER start services before writing their configuration
NEVER verify service state before starting the service