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
    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?


1 Answer 1


Q: "If the variable item.ppsize is not set exclude that parameter."

A: Set the default value to the special variable omit

    pp_size: "{{ item.ppsize | default(omit) }}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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