Passing variables to a template / jinja2 ??

83 views
Skip to first unread message

nadim mansour

unread,
Oct 31, 2018, 7:03:37 AM10/31/18
to Ansible Project
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 ?

Mohan L

unread,
Oct 31, 2018, 8:43:05 AM10/31/18
to Ansible Project



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

Brian Coca

unread,
Nov 1, 2018, 5:31:36 PM11/1/18
to ansible...@googlegroups.com
you can also use vars_prompt to create the variables
https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html


--
----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages