Passing variables to a template / jinja2 ??

I have an http.conf where some values will be variables passed by the user

where should I put the variables and how the file should look can someone advice ?

1). Send all your user input to ansible playbook command using —extra-vars. You can also pass as json and yaml file.

Example: # ansible-playbook site.yml —extra-vars “http_server_root=/var/www/html http_listen=8080 http_user=apache http_group=apache”

https://docs.ansible.com/ansible/2.7/user_guide/playbooks_variables.html#passing-variables-on-the-command-line

2). Create a template for your http.conf file with variable which you are passing via —extra-vars.

http.conf.j2

ServerRoot {{ http_server_root }}

Listen {{ http_listen }}

User {{ http_user }}

Group {{ http_group }}

3). Use template module to copy the config to target.

  • name: Install main configuration file

template:

src: httpd.conf.j2

dest: /etc/httpd/conf/httpd.conf

you can also use vars_prompt to create the variables
https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html