Ansible Template - Jinja2 |
ansible playbook, jinja2, jinja2 template, jinja2 tutorial, jinja2 template example, ansible template, ansible template example, ansible template tutorial, ansible template variables, ansible template default value, ansible playbook examples, ansible playbook tutorial, ansible tutorial for beginners, ansible tasks, ansible, ansible tutorial, ansible example, ansible facts, ansible linux, ansible best practices, ansible variables, ansible variables list, ansible global variable
How to Update variables in Jinja2 templates ?
How to work in Ansible Jinja2 Template?
A Ansible template is a simple text file that contains your configuration parameters and replace dynamic values are given as variables. this template file use Jinja2 templating engine with .j2 extension. we can define variables in double curly braces like {{ variable_name }}
To Create Ansible Templating (Jinja2)
cd /etc/ansiblevi templete.j2
This is my website {{ website }} and it's running on {{ server }} since {{ year }}
In this template we are using three variables , define in playbook
To create ansible playbook with any suitable name as you wish
vi template.yml
- hosts: all
gather_facts: false
vars:
- website: linuxtopic.com
- server: apache
- year: 2015
tasks:
- name: update configuration using templates
template: src=template.j2 dest=/tmp/template mode=0755 owner=apache group=apache
To execute ansible playbook with template module - we execute it only localhost by -l option
ansible-playbook -l 127.0.0.1 template.yml
To verify updated files, replace by jinja2 template
ll /tmp/template
cat /tmp/template
End of this ansible templating tutorial, We successfully replace files with variable value in our configuration file.
Your support is must so Please Like, share and comment on this ansible Templating (Jinja2) artical.
Thanks,
www.linuxtopic.com
good thanks
ReplyDeletekeep it do
ReplyDelete