我正在尝试将服务器的主机名写入配置文件,但它给我带来了问题。你能帮忙看一下代码吗?
---
- 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”
答案1
如果要将domain
变量包含到hostname
,则需要使用以下语法:
hostname: 'serv1.{{ domain }}'
在lineinfile
任务中:
line : 'authorization-uri: https://{{ hostname }}/key/auth/mvn/vars/lenz/svc/chk'