Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task failing when running on check mode #39

Open
bengoa opened this issue Aug 15, 2019 · 0 comments
Open

Task failing when running on check mode #39

bengoa opened this issue Aug 15, 2019 · 0 comments

Comments

@bengoa
Copy link

bengoa commented Aug 15, 2019

Hello guys,

The task bellow is failing when running on check mode:

Task:

- name: Assert postfix check is successful, if not, show friendly message
  assert:
    msg: "`postfix check` failed. postfix has not been reloaded but some configurations might have been read by postfix. Run `postfix check`, find out error, fix it and deploy again"
    that:
      - register_postfix_check.rc == 0

Error:

TASK [external/postfix : Assert postfix check is successful, if not, show friendly message] ***********************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The conditional check 'register_postfix_check.rc == 0' failed. The error was: error while evaluating conditional (register_postfix_check.rc == 0): 'dict object' has no attribute 'rc'"}

This is happening because assert tries to evaluate a variable that wasn't created on the previous task (Validate all configurations) because command module doesn't run in check mode in some circunstances:

"Check mode is supported when passing creates or removes. If running in check mode and either of these are specified, the module will check for the existence of the file and report the correct changed status. If these are not supplied, the task will be skipped."

Adding a when: not ansible_check_mode (available since Ansible 2.1) should fix it.

I can open a PR with this simple patch if you need it.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant