3

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.

vars:
    host_fqdn:  server
    host_fqdn: |
    {%  if  'lab.com' in {{  host_fqdn }} %}
        {%  host_fqdn = "{{ host_fqdn }}" %}
    {% else %}
        {%  host_fqdn = "{{ host_fqdn }}.lab.com" %}
    {%  endif %}
Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Pandu
  • 129

1 Answers1

0

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' }}"
Pandu
  • 129