# Playbook fails on check but runs fine otherwise

**URL:** <https://forum.ansible.com/t/playbook-fails-on-check-but-runs-fine-otherwise/20813>\
**Category:** Ansible Project\
**Created:** [March 9, 2016, 1:09pm UTC](https://forum.ansible.com/t/playbook-fails-on-check-but-runs-fine-otherwise/20813 "2016-03-09T13:09:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_De\_Blende](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Tom\_De\_Blende](https://forum.ansible.com/u/Tom_De_Blende)\
**Post date:** [March 9, 2016, 1:09pm UTC](https://forum.ansible.com/t/playbook-fails-on-check-but-runs-fine-otherwise/20813/1 "2016-03-09T13:09:24Z")

</div>

Hi all,

I have a playbook which installs an rpm. The rpm requires input (yikes), so I have written an expect script that is executed. So sadly the yum module is not an option, but it all works fine.

I only want to run the script though, when the rpm is not already present. So I have this:

`

- name: Check if managesoft is installed  
command: rpm -q managesoft  
ignore\_errors: true  
failed\_when: rpm\_check.rc \> 1  
changed\_when: false  
register: rpm\_check  
when: ansible\_os\_family == ‘RedHat’  
tags: flexera

- name: Install expect  
yum:  
name: “expect”  
state: installed  
when: rpm\_check.stdout.find(‘is not installed’) != -1 and ansible\_os\_family == ‘RedHat’  
tags: flexera

`

Now when I run the playbook in check mode like this:

`  
ansible-playbook --tags=“flexera” --limit=“x.x.x.x” peganonprd.yml -vC

`

This happens:

`

TASK [flexera : Install expect] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [x.x.x.x]: FAILED! =\> {“failed”: true, “msg”: “ERROR! The conditional check ‘rpm\_check.stdout.find(‘is not installed’) != -1 and ansible\_os\_family == ‘RedHat’’ failed. The error was: ERROR! error while evaluating conditional (rpm\_check.stdout.find(‘is not installed’) != -1 and ansible\_os\_family == ‘RedHat’): ERROR! ‘dict object’ has no attribute ‘stdout’\n\nThe error appears to have been in ‘/etc/ansible/roles/flexera/tasks/package.yml’: line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Install expect\n ^ here\n”}

`

But if I run it without the -C, it goes through without issues. Which is annoying as I use -C frequently…

How can this be explained?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 9, 2016, 2:34pm UTC](https://forum.ansible.com/t/playbook-fails-on-check-but-runs-fine-otherwise/20813/2 "2016-03-09T14:34:04Z")

</div>

The command module does not run in check mode, it has no way of knowing that the command is safe. The subsequent task depends on that so it fails when the output is skipped.

use `always_run: True` on the command task to force execution in check mode.

---

<div class="post-metadata">

**Author:** ![Tom\_De\_Blende](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@Tom\_De\_Blende](https://forum.ansible.com/u/Tom_De_Blende)\
**Post date:** [March 9, 2016, 3:19pm UTC](https://forum.ansible.com/t/playbook-fails-on-check-but-runs-fine-otherwise/20813/3 "2016-03-09T15:19:35Z")

</div>

Thank you, that was indeed the problem!
