# File with variables (template)

**URL:** <https://forum.ansible.com/t/file-with-variables-template/28926>\
**Category:** Ansible Project\
**Created:** [November 2, 2018, 6:47am UTC](https://forum.ansible.com/t/file-with-variables-template/28926 "2018-11-02T06:47:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nadim\_mansour](https://avatars.discourse-cdn.com/v4/letter/n/a698b9/32.png) [@nadim\_mansour](https://forum.ansible.com/u/nadim_mansour)\
**Post date:** [November 2, 2018, 6:47am UTC](https://forum.ansible.com/t/file-with-variables-template/28926/1 "2018-11-02T06:47:17Z")

</div>

If I have a file and the user wants to pass variables for this file (example: http.conf)

should I convert the file to http.conf.j2 ? when copied to the server it will be read as http.conf or http.conf.j2 ?  
where should be the location of this file ? under template folder in ansible project ?

How can i convert my file to .j2 ?

---

<div class="post-metadata">

**Author:** ![Foss\_Geek](https://avatars.discourse-cdn.com/v4/letter/f/df705f/32.png) [@Foss\_Geek](https://forum.ansible.com/u/Foss_Geek)\
**Post date:** [November 2, 2018, 7:54am UTC](https://forum.ansible.com/t/file-with-variables-template/28926/2 "2018-11-02T07:54:22Z")

</div>

Did you get any chance to read this template module doc? [https://docs.ansible.com/ansible/latest/modules/template\_module.html](https://docs.ansible.com/ansible/latest/modules/template_module.html)

Just read a very basic usage of template module: [http://www.mydailytutorials.com/ansible-template-module-examples/](http://www.mydailytutorials.com/ansible-template-module-examples/)

> If I have a file and the user wants to pass variables for this file (example: http.conf)
> 
> should I convert the file to http.conf.j2 ? when copied to the server it will be read as http.conf or http.conf.j2 ?  
> where should be the location of this file ? under template folder in ansible project ?
> 
> How can i convert my file to .j2 ?

Here is example:

- name: Install http configuration file  
template:  
src: /path/to/httpd.conf.j2  
dest: /etc/httpd/conf/httpd.conf

The template files will usually have the .j2 extension, which denotes the Jinja2 templating engine used. You can keep the .j2 file either under your role’s template directory or template directory under your playbook directory. You no need to do any conversion. During the playbook execution, the variables in .j2 file will be replaced with the relevant values as long as the variables are defined.
