I’m here to bring an issue with Ansible dry-run (–check) mode. I have been facing a curious situation where package installation made using Playbooks and run in a dry-run mode is not working as expected. Using register+debug module it’s possible to see that the package has been successfully installed, but when I try to use that installed package in later task, Ansible fails.
The whole point of check mode is that it doesn’t make changes to the system. If you want things to change (e.g. packages to install), don’t run in check mode.
The point is, a CI tool such as Travis, Tower… will report error on that task, but actually there is no error at all (normal running). In addition, package installing task is just 0,5% of the whole deployment project and thinking deeper, every task does changes on the systems. Many ansible other modules I have used do work in --check mode, except package manager which I am reporting here.
As flowerysong says, --check means, do not make any changes to the system. So you cannot run ansible in check-mode and then expect an assertion that a change was made to succeed. Similarly, you cannot expect that running a second task which depends on the first task to have changed the system in some way to succeed in check-mode because the change will not have been made to the system.
Ok guys, I got the point “–check doesn’t make any changes to the system” after making more tests with tasks coupling (Task2 relies on previous executed Task1), --check mode will never work for these cases. Therefore, i will change my test pipeline to discard dry-run mode which has been thought to do a “Functional test”.
An alternative to make check work involves some code changes.
You have "check_mode: no" to make a task run in check_mode.
You can also check if Ansible run in check mode to skip some task, "when: not ansible_check_mode"