Cubis Engineers

Safe automation workflow

Review the target and changes, test one server, roll out in small batches, and verify the result.

Cloud & infrastructureIntermediateUpdated Aug 13, 2026ansibleautomationcheck-moderolloutvault

Treat every Ansible run as a deployment. The playbook, inventory, variables, target selection, and Ansible version together define what will happen.

Validate before changing servers

Terminal
ansible-playbook playbooks/server-baseline.yml --syntax-check
ansible-playbook playbooks/server-baseline.yml --list-hosts
ansible-playbook playbooks/server-baseline.yml --list-tasks
ansible-playbook playbooks/server-baseline.yml \
  --check --diff --limit web-01

Check mode asks supported modules to report what they would change without applying it. Diff mode shows before-and-after content for modules that support diffs. Some tasks cannot simulate accurately, and diffs can reveal secrets, so use diff: false on sensitive tasks.

Roll out in a controlled order

Confirm the target

Use --list-hosts and read the output. Keep production and test inventory separate.

Preview one non-production host

Run with --check --diff --limit HOST. Review every reported change.

Apply to one host

Remove --check, keep --limit HOST, and monitor the service while Ansible runs.

Verify the service

Run its health check, inspect the journal, and confirm the expected user path before expanding the target.

Roll out in batches

Set serial in the play and keep enough healthy capacity while each batch changes.

Useful run controls

CommandPurpose
--limit web-01Run only against one host or pattern
--checkPreview changes supported by each module
--diffShow configuration differences; may expose sensitive data
--stepConfirm tasks one at a time during troubleshooting
--start-at-task 'Name'Resume at a named task after understanding the earlier state
--tags nginxRun only tasks carrying the selected tag
--forks 5Limit concurrent host work from the control node

Protect secrets

Encrypt a variables file with Ansible Vault:

Terminal
ansible-vault create group_vars/all/vault.yml
ansible-vault edit group_vars/all/vault.yml
ansible-playbook playbooks/server-baseline.yml --ask-vault-pass

For CI, retrieve the vault password or encrypted values from the team’s secret manager. Do not pass secrets on the command line, print them in task output, or expose them through --diff. Add no_log: true to tasks whose inputs or results contain secrets, while remembering that this also removes useful troubleshooting output.

Verify and record the run

Terminal
ansible all -m ansible.builtin.service_facts
ansible web -m ansible.builtin.uri \
  -a 'url=http://127.0.0.1/health.html return_content=true'

Record the repository commit, inventory source, target pattern, operator or CI job, start and finish time, and verification result. If a playbook changes application state or data, document a rollback that has been tested independently of Ansible.

Official references

On this page