6

Is there a way to exclude a parameter entirely if a variable is not set? I do not want to use a default value for this, I simply do not way the parameter referenced at all.

For example,

---
- name: manage_aix_lvm | creating new VG
  # https://docs.ansible.com/ansible/latest/modules/aix_lvg_module.html#aix-lvg-module
  aix_lvg:
    force: "{{ item.force | default('no') }}"
    pp_size: "{{ item.ppsize }}"
    pvs: "{{ item.disks | join(',') }}"
    vg: "{{ item.vgname }}"
    state: present
  become: true
  loop: "{{ lvm_groups }}"

In the event that variable item.ppsize is not set I want to exclude that entire parameter from being included. The reason for this is that this is an optional parameter, and if not set, the Operating System will automatically calculate the value.

Is this possible within a single task? Or will I need to create multiple Tasks/Resources to check if item.ppsize is set and redirect to different tasks/resources?

Thanks.

6

Q: "In the event that variable item.ppsize is not set I want to exclude that entire parameter from being included."

A: Use the default filter to omit module parameters using the special omit variable

    pp_size: "{{ item.ppsize|default(omit) }}"
2
  • Thankyou! I knew I was missing something. Much obliged :)
    – Dave L
    Jun 28 '19 at 19:48
  • It is customary to upvote a good question, if it's worth answering, and a good answer, if it's good enough to accept. :) Jun 28 '19 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.