I\'m using Ansible with Jinja2 templates, and this is a scenario that I can\'t find a solution for in Ansible\'s documentation or googling around for Jinja2 examples. Here\'
Something like this would work, but it's ugly. And as @podarok mentioned in his answer, it's likely unnecessary depending on exactly what you're attempting to do:
- name: set default
set_fact: new_ansible_var= ""
- name: set to 'a'
set_fact: new_ansible_var= "a"
when: "{{ existing_ansible_var }} == string1"
- name: set to 'b'
set_fact: new_ansible_var= "b"
when: "{{ existing_ansible_var }} == string2"
etc.