Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

backwards compatibility - How to suppress "Unsupported parameters" error in Ansible?

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
question from:https://stackoverflow.com/questions/65910893/how-to-suppress-unsupported-parameters-error-in-ansible

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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) }}"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...