July 2017
Intermediate to advanced
266 pages
6h 36m
English
Jinja provides an excellent solution for manipulating strings and concatenating text (joining it with other text). For example, we might want to create a unique MOTD file by adding some additional information to the MOTD contents based on perhaps the hostname. This could be easily achieved via the following ansible playbook and Jinja syntax.
playbook.yml:
# Example playbook using simple JINJA2 variable substitution- hosts: 127.0.0.1 user: root vars: motd: "Welcome to your Linux Box! You are connected to {{ inventory_hostname_short }}" tasks: - name: Update the /etc/motd copy: content=‘{{motd}}' dest='/etc/motd' force='yes'
As we can see, the example shows how easy it is to concatenate string variables ...
Read now
Unlock full access