patternModerate
Ansible: Exclude a parameter if variable is not set
Viewed 0 times
setexcludevariableansibleparameternot
Problem
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,
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.
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.
Solution
Q: "If the variable item.ppsize is not set exclude that parameter."
A: Set the default value to the special variable omit
A: Set the default value to the special variable omit
pp_size: "{{ item.ppsize|default(omit) }}"
Context
StackExchange DevOps Q#8497, answer score: 11
Revisions (0)
No revisions yet.