diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /lib/ansible/plugins/filter/ternary.yml | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream.tar.xz ansible-core-upstream.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ansible/plugins/filter/ternary.yml')
-rw-r--r-- | lib/ansible/plugins/filter/ternary.yml | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/ansible/plugins/filter/ternary.yml b/lib/ansible/plugins/filter/ternary.yml new file mode 100644 index 0000000..50ff767 --- /dev/null +++ b/lib/ansible/plugins/filter/ternary.yml @@ -0,0 +1,44 @@ +DOCUMENTATION: + name: ternary + author: Brian Coca (@bcoca) + version_added: '1.9' + short_description: Ternary operation filter + description: + - Return the first value if the input is C(True), the second if C(False). + positional: true_val, false_val + options: + _input: + description: A boolean expression, must evaluate to C(True) or C(False). + type: bool + required: true + true_val: + description: Value to return if the input is C(True). + type: any + required: true + false_val: + description: Value to return if the input is C(False). + type: any + none_val: + description: Value to return if the input is C(None). If not set, C(None) will be treated as C(False). + type: any + version_added: '2.8' + notes: + - Vars as values are evaluated even when not returned. This is due to them being evaluated before being passed into the filter. + +EXAMPLES: | + # set first 10 volumes rw, rest as dp + volume_mode: "{{ (item|int < 11)|ternary('rw', 'dp') }}" + + # choose correct vpc subnet id, note that vars as values are evaluated even if not returned + vpc_subnet_id: "{{ (ec2_subnet_type == 'public') | ternary(ec2_vpc_public_subnet_id, ec2_vpc_private_subnet_id) }}" + + - name: service-foo, use systemd module unless upstart is present, then use old service module + service: + state: restarted + enabled: yes + use: "{{ (ansible_service_mgr == 'upstart') | ternary('service', 'systemd') }}" + +RETURN: + _value: + description: The value indicated by the input. + type: any |