# error in jinja2 template

**URL:** <https://forum.ansible.com/t/error-in-jinja2-template/38632>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [December 19, 2023, 3:50am UTC](https://forum.ansible.com/t/error-in-jinja2-template/38632 "2023-12-19T03:50:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thirumalairaja](https://avatars.discourse-cdn.com/v4/letter/t/c6cbf5/32.png) [@thirumalairaja](https://forum.ansible.com/u/thirumalairaja)\
**Post date:** [December 19, 2023, 3:50am UTC](https://forum.ansible.com/t/error-in-jinja2-template/38632/1 "2023-12-19T03:50:54Z")

</div>

Hi Team,  
below is my playbook and j2 template i was failed to create a file actually i am not comfortable wil jinja2 if any one can guide me

playbook:

- name: read data  
set\_fact:  
vm\_data: “{{ lookup(‘file’, ‘variables/vm\_data.yaml’) | from\_yaml }}”  
tags:

- read\_vm\_data

- name: getting IP\_scope  
getip\_scope:  
csv\_file: template/subnetsheet.csv  
location\_network: “{{ location\_network }}”  
register: vm\_data  
tags:

- getting\_ip

- name: Free Ip-address  
script:  
cmd: ip.py “{{ vm\_data.details.IP\_Scope }}” “{{ vm\_data.details.IP\_Gateway }}”  
executable: python  
register: ip  
delegate\_to: “{{ delegate\_host }}”  
tags:

- getting\_ip

- name:  
debug:  
var: ip.stdout  
tags:

- getting\_ip

- name: set\_fact  
set\_fact:  
vDS: “{{ vm\_data.details.vDS }}”  
vPG\_Name: “{{ vm\_data.details.vPG\_Name }}”  
vm\_ipv4\_address: “{{ ip.stdout | from\_json | json\_query(‘vm\_ipv4\_address’) }}”  
vm\_ipv4\_netmask: “{{ ip.stdout | from\_json | json\_query(‘vm\_ipv4\_netmask’) }}”  
vm\_ipv4\_gateway: “{{ ip.stdout | from\_json | json\_query(‘vm\_ipv4\_gateway’) }}”  
tags:

- [get\_variables.tf](http://get_variables.tf)

- name: creating [var.tf](http://var.tf)  
template:  
src: template/win\_variable.tf.j2  
dest: terraform\_config\_files/Windows/[variables.tf](http://variables.tf)  
tags:

- [get\_variables.tf](http://get_variables.tf)

jinja2 template:

locals {  
vm = yamldecode(file(“/runner/project/variables/vm\_data.yaml”))  
}

variable “vsphere\_insecure” {  
type = bool  
default = true  
}

#credentials  
variable “vsphere\_username” {  
type = string  
sensitive = true  
}  
variable “vsphere\_password” {  
type = string  
sensitive = true  
}  
variable “domain\_admin\_username” {  
type = string  
sensitive = true  
}  
variable “domain\_admin\_password” {  
type = string  
sensitive = true  
}  
variable “vm\_admin\_password” {  
type = string  
sensitive = true  
}  
variable “template\_name” {  
type = string  
default = “z\_Templates/{{vsphere\_template}}”  
}

variable “vsphere\_network” {  
type = string  
default = “{{ansible\_facts[vDS]}}/{{ansible\_facts[vPG Name]}}”  
}

variable “vm\_ipv4\_address” {  
type = string  
default = {{ ansible\_facts[‘vm\_ipv4\_address’] }}  
}

variable “vm\_ipv4\_netmask” {  
type = string  
default = {{ ansible\_facts[‘vm\_ipv4\_netmask’] }}  
}

variable “vm\_ipv4\_gateway” {  
type = string  
default = {{ ansible\_facts[‘vm\_ipv4\_gateway’] }}  
}

---

<div class="post-metadata">

**Author:** ![Prady\_A](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/prady_a/32/4792_2.png) [@Prady\_A](https://forum.ansible.com/u/Prady_A)\
**Post date:** [December 19, 2023, 5:55am UTC](https://forum.ansible.com/t/error-in-jinja2-template/38632/2 "2023-12-19T05:55:19Z")

</div>

Hi

Did you run your playbook or not ?  
What’s the output so that it will be easy to diagnose

Thanks
