# issue with ansible dry-run mode (--check) on package installation tasks (yum and apt modules)

**URL:** <https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495>\
**Category:** Ansible Project\
**Created:** [May 10, 2018, 4:11am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495 "2018-05-10T04:11:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![js.a](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@js.a](https://forum.ansible.com/u/js.a)\
**Post date:** [May 10, 2018, 4:11am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/1 "2018-05-10T04:11:02Z")

</div>

Hello guys.

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.

**My Playbook:**

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [May 10, 2018, 5:06am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/2 "2018-05-10T05:06:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![js.a](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@js.a](https://forum.ansible.com/u/js.a)\
**Post date:** [May 11, 2018, 2:55am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/3 "2018-05-11T02:55:54Z")

</div>

@flowerysong

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.

---

<div class="post-metadata">

**Author:** ![tkuratom](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tkuratom](https://forum.ansible.com/u/tkuratom)\
**Post date:** [May 11, 2018, 3:10am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/4 "2018-05-11T03:10:51Z")

</div>

The yum task succeeded. It’s the subsequent fail that is failing. You can make any other module +fail react in the same way:

- file: path=/var/tmp/i\_do\_not\_exist\_yet state=directory

- stat:  
path: /var/tmp/i\_do\_not\_exist\_yet  
register: file

- fail:  
msg: “File i\_do\_not\_exist\_yet doesn’t exist!”  
when: file.stat.exists == False

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.

-Toshio

---

<div class="post-metadata">

**Author:** ![js.a](https://avatars.discourse-cdn.com/v4/letter/j/a587f6/32.png) [@js.a](https://forum.ansible.com/u/js.a)\
**Post date:** [May 11, 2018, 8:42pm UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/5 "2018-05-11T20:42:30Z")

</div>

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”.

Thank you very much for helping me.

j

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 12, 2018, 10:54am UTC](https://forum.ansible.com/t/issue-with-ansible-dry-run-mode-check-on-package-installation-tasks-yum-and-apt-modules/27495/6 "2018-05-12T10:54:46Z")

</div>

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"
