dynamically set variables with set_fact

I want to dynamically set a value to a variable using set_fact, however, it always uses the first value:

  • name: Global_vars - get env info
    set_fact:
    jm_env: “{{lookup(‘env’, ‘Environment’)}}”
    l_env: “{% if ‘{{jm_env}}==Develop’ %}d{% elif ‘{{jm_env}}==Staging’%}s{% else %}p{% endif %}”

l_env variable always returns d

I have tried putting quotes in different places, etc with no success.

Correct syntac
l_env: "{% if jm_env=='Develop' %}d{% elif jm_env=='Staging'%}s{% else %}p{% endif %}"

I also suspect that you need to split them so jm_env is in one task and l_env in another task.