I am using a the quiet
parameter in the assert
module for tasks where the output is too verbose. The quiet
parameter was introduced in Ansible 2.8, but unfortunately, my code sometimes needs to run on Debian Buster, which still comes with Ansible 2.7.
In that case, Ansible fails with the fatal error "Unsupported parameters for (assert) module: quiet". Since this is only a cosmetic parameter, I want Ansible 2.7 to ignore this parameter and continue.
Is there a way to add this parameter in my task so that Ansible 2.8 is nice and quiet, but the task still runs in Ansible 2.7?
- name: Silent assert
assert:
that:
- true
quiet: yes
There is an omit
filter which can help in bypassing some parameters if they are not applicable. For this purpose, we can define a variable that will be set to true
for Ansible version 2.8 or greater. Then this variable can be passed to the quiet
parameter of assert
module in combination with omit
.
Example:
- set_fact:
quiet_assert: true
when: ansible_version.full is version('2.8', '>=')
- assert:
that:
- true
quiet: "{{ quiet_assert|default(omit) }}"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments