On Tue, 7 Jan 2020 05:41:12 -0800 (PST)
Yehuda Pinhas <
yuda....@gmail.com> wrote:
> qos_policy: qos-nested-new-10m
> when: "{{ bandwidth_mb }} == '10'"
> qos_policy: qos-nested-new-20m
> when: "{{ bandwidth_mb }} == '20'"
>
> #### Modify: ####
> bandwidth_mb: 10
>
> *I'm trying to create a condition for the qos_policy variable:*
> if bandwidth_mb = 10 then qos_policy = qos-nested-new-10m
> if bandwidth_mb = 20 then qos_policy = qos-nested-new-20m
Concatenate the strings. For example
- hosts: localhost
vars:
bandwidth_mb: 10
tasks:
- set_fact:
qos_policy: "{{ 'qos-nested-new-' +
bandwidth_mb|string +
'm' }}"
- debug:
var: qos_policy
gives
ok: [localhost] => {
"qos_policy": "qos-nested-new-10m"
}
> *The errors im receiving on all my previous attempts to do this code are:*
> 1. invalid syntax
> when: "{{ bandwidth_mb }} == '10'"
The conditions are expanded by default. Try
- debug:
msg: Bandwidth is 10 MB
when: bandwidth_mb == 10
HTH,
-vlado