Ansible Jinja2 Template Tutorial Server Automation

preview_player
Показать описание
Templates in Ansible give you so many options to manage files and configuration files. With Jinja2, we can use If/else conditions and create files based on inventory groups. Once you understand these basics, you'll be able to take your ansible knowledge to the next level.

In this demo on using templates in Ansible, I’m going to cover the following:

• Ansible_managed – How to let people know the file is managed by Ansible
• Simple examples of using Ansible facts in templates
• Using playbook variables in templates
• If else conditionals for different outputs
• Create /etc/hosts files using templates and Jinja2

More information can be found here:

Subscribe for more videos like this

#Ansible #Jinja2 #Automation
Рекомендации по теме
Комментарии
Автор

Really you explained jinja in a very good way.
Thanks 🙏 alot

RABWA
Автор

How to access environment variable in Jinja template

abhinav
Автор

I did the same (identical comment as you have it); But it just displays : Ansible managed
im not sure what im doing wrong!

ansible.cfg
[defaults]
ansible_managed="# This file is managed by Ansible. DO NOT EDIT MANUALLY"

sample playbook:
- name: copy authorized_keys file to .ssh for devops user
template:
src:
dest:
owner: devops
group: devops
mode: 0644

authorized_keys_devops:
{{ ansible_managed }}
KEY FILE HERE
KEY FILE HERE

RESULT:
Ansible Managed
KEY FILE HERE
KEY FILE HERE

beydoin