Configuring templates
In infrastructure management, we often face situations when we have to push files to multiple hosts but the information in the files is host-specific such as the hostname, IP address, and so on. In Salt, we can achieve the same objectives using templates, and in this recipe, we are going to learn about how to use templates.
How to do it...
We will use the minion stgdc1log01
that we configured in the last recipe, Using state modules.
Create a new state in the staging environment named
hostconfig
by creating a directory calledhostconfig
in the base directory of the staging environment. Create a directory calledfiles
in thehostconfig
directory and also a file namedinit.sls
.Edit the
init.sls
file to have the following contents:hosts_file: file.managed: - name: /etc/hosts - source: salt://hostconfig/files/hosts - user: root - hroup: root - mode: 644 - template: jinja - context: local_ip_address: {{ grains['ip4_interfaces']['eth1'][0]...