[英]ansible doesent assign jinja2 variable values
以下任务确实按预期工作。 它应该在远程主机上创建icinga2配置文件。 它创建文件,但不转换为定义的变量。
Ansible任务:
- name: create check for cq6-server
template:
src=icinga-cq6-template.j2
dest=/etc/icinga2/zones.d/icinga.dus3/{{ ansible_hostname }}-cq6-{{ project_name }}-{{ cq_role_1 }}.conf
mode=0644
when: "'cq6-servers' in group_names or 'cq6-dispatcher' in group_names"
delegate_to: "{{ monitoring_server }}"
notify: restart icinga2
它在Icinga2服务器上创建以下文件:
{{ ansible_hostname }}-cq6-{{ project_name }}-{{ cq_role_1 }}.conf
该文件仍带有所有方括号,即使{{ ansible_managed }}
有谁知道为什么这样做,但可以处理其他任务/模板吗?
建议使用yaml dict表示法,即
- name: create check for cq6-server
template:
src: icinga-cq6-template.j2
dest: "/etc/icinga2/zones.d/icinga.dus3/{{ ansible_hostname }}-cq6-{{ project_name }}-{{ cq_role_1 }}.conf"
mode: 0644
when: "'cq6-servers' in group_names or 'cq6-dispatcher' in group_names"
delegate_to: "{{ monitoring_server }}"
notify: restart icinga2
但是可能您的变量为空,所以我建议使用调试来验证,例如
- debug:
var: "{{ ansible_hostname }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.