How to pass in hostname from variable and update config file with the hostname in ansible

I am trying to write the hostname of a server into the config file, but its giving me issues. can you help take a look at the code?

---
- name: Update host.
  hosts: all
  connection: local
    # Default Value
    domain: '{{ default_domain }}'
    hostname: “serv1.{{ '{{' }} domain {{ '}}' }}"
    tasks:
    - name: Update hostname config file
      block:
        - lineinfile:
            path: /home/test/conf.yml
            state: present
            regexp: 'authorization-uri:(.*)$'
            line: "authorization-uri: https://{{ serv1.{{ '{{' }} domain {{ '}}' }}/key/auth/mvn/vars/lenz/svc/chk”

Domain = serv1
Hostname = app2
Output should be:
https://serv1.app2/key/auth/mvn/vars/lenz/svc/chk”

Solution 1:

If you want to include domain variable to hostname, you need to use following syntax:

hostname: 'serv1.{{ domain }}'

And in the lineinfile task:

line : 'authorization-uri: https://{{ hostname }}/key/auth/mvn/vars/lenz/svc/chk'