ansible --check mode for shift left

Hi,

I’m trying to add some “shift left” to my Ansible, so that mistakes don’t creep in. Firstly, I thought I would run --check (perhaps as a git pre-commit hook or perhaps in Jenkins pipeline eventually). So, I tried it locally. Unfortunately it bombs out in several places, as some tasks are reliant on the output of other tasks. Not a great problem, as I’ve added

when: not ansible_check_mode

to those tasks.

Is there a better way of achieving this? Particularly it would be useful to check that variables are set to something sensible (catch typos or just missed variables) BEFORE it goes into production. We have vars files based on environments, so these don’t get checked until we actually deploy to that environment.

Hi Steve,

Take a look at check_mode and assess your playbook to see which features are you can safely change, ie those that do not make change.

https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html

Regards
Steve Maher

Providing default values for missing outputs might be a better option
in some cases. It would be good to see the particular case(s).

Try a dry run with —check on a remote host (—limit $HOST). I forgot, —check does a dry run.

Mike