Search keyword in "host_fqdn" variable. If the value has "lab.com" keyword in it, it should directly store the value to "host_fqdn" again or else it should add "lab.com" keyword to the value and store it to "host_fqdn" variable.

    host_fqdn:  server
    host_fqdn: |
    {%  if  'lab.com' in {{  host_fqdn }} %}
        {%  host_fqdn = "{{ host_fqdn }}" %}
    {% else %}
        {%  host_fqdn = "{{ host_fqdn }}.lab.com" %}
    {%  endif %}

It cannot be done through vars, but it can be done through set_fact as below

  - set_fact:
          host_fqdn:  "{{ host_fqdn if 'lab.com' in host_fqdn else host_fqdn  ~'.lab.com' }}"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.