dcg

Ansible

infrastructure.ansible

Protects against destructive Ansible operations like dangerous shell commands and unchecked playbook runs

  • 4blocking rules
  • 7safe patterns
  • 1Critical
  • 2High
  • 1Medium
~/.config/dcg/config.toml
[packs]
enabled = ["infrastructure.ansible"]

Evaluated when a command contains ansible, playbook.

Blocking rules

Each rule ID is infrastructure.ansible:<name>. Use it in allowlists and [policy.rules].

  1. shell-rm-rf

    Critical

    Ansible shell/command with 'rm -rf' is destructive. Review carefully.

    Explanation
    Running 'rm -rf' via Ansible shell or command module executes destructive deletion across all targeted hosts simultaneously. This multiplies the impact compared to running it locally: - Files deleted on every host in inventory or pattern - No confirmation or dry-run by default - Parallel execution means rapid, widespread destruction - Cannot be undone without backups on each host Safer alternatives: - Use file module with state=absent for managed deletion - Add --check flag to preview which hosts would be affected - Use --limit to restrict to specific hosts first - Verify target path with debug module before deletion
  2. playbook-all-hosts

    High

    ansible-playbook without --check or --limit may affect all hosts. Use --check first.

    Explanation
    Running ansible-playbook without --check or --limit applies changes to all hosts in the inventory. This is risky for destructive playbooks: - Every host matching the play's pattern is affected - Mistakes propagate to entire infrastructure at once - No opportunity to verify changes before they're applied - Rollback may be difficult or impossible Safer alternatives: - Add --check --diff to preview changes - Use --limit host1,host2 to test on subset - Add serial: 1 to playbook for rolling updates - Review the playbook tasks before running
  3. shell-reboot

    High

    Ansible shell/command with reboot/shutdown affects system availability.

    Explanation
    Rebooting or shutting down systems via Ansible affects all targeted hosts at once. This can cause service outages across your infrastructure: - All services on affected hosts become unavailable - No graceful draining of connections or traffic - Database transactions may be interrupted - Load balancer health checks will fail Safer alternatives: - Use the reboot module which handles wait_for_connection - Add serial: 1 to playbook for rolling reboots - Use --limit to test on single host first - Coordinate with maintenance windows
  4. extra-vars-delete

    Medium

    Ansible extra-vars contains potentially destructive keywords. Review carefully.

    Explanation
    Extra variables containing destructive keywords like 'delete', 'remove', 'destroy', or 'drop' may trigger conditional destructive actions in playbooks: - Variables may control whether resources are deleted - Typos in variable values could trigger unintended paths - Variable precedence may override safer defaults Safer alternatives: - Review playbook to understand how variables are used - Add --check to see what tasks would run - Use --limit to test on single host first - Consider using vault-encrypted vars for destructive flags

Safe patterns

Checked first. A command that matches one is never blocked by this pack.

  • ansible-check
  • ansible-list-hosts
  • ansible-list-tasks
  • ansible-syntax
  • ansible-inventory
  • ansible-doc
  • ansible-config