Changing variable value based on another variable value

Hi guys!

This is my code:

  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

Thank you vladimir!
working now

בתאריך יום שלישי, 7 בינואר 2020 בשעה 16:34:47 UTC+2, מאת Vladimir Botka: