2

I want to copy file using jinja2 templating in ansible.

I have one file inside templates/file.j2 and inside that file I have one variable defined

fos.broker.host={{ fos.broker.host }}

Inside group_vars/stage I have the value of this variable as

fos.broker.host: 'api_vl.vlstage.fidor.de'

And finally I am deploying it via main.yml and it looks like.

---
- hosts: vlstage
  vars_files:
    - group_vars/vlstage

  tasks:
  - name: copy files to host
    template: src=templates/file.j2 dest=/opt/tomcat/lib/file.conf 
    backup=yes owner=zoaib group=zoaib

but when I run command ansible-playbook -i hosts main.yml -u zoaib

I get below error:

TASK [copy files to host] *************************************************************************************************************************************************************
fatal: [s-vl-idl-app02.fidor.intern]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'fos' is undefined"}

any leads to solve the issue ?

Aziz Zoaib
  • 661
  • 8
  • 21

1 Answers1

4

Don't use dots in variable names. Dot notation is used to refer to dictionary keys.

Read What Makes A Valid Variable Name:

foo-port, foo port, foo.port and 12 are not valid variable names.


Although in reality, it is possible to use a variable with dots in their name and refer to its value it with the vars lookup plugin:

fos.broker.host={{ lookup('vars', 'fos.broker.host') }}
techraf
  • 64,883
  • 27
  • 193
  • 198