Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Salt Cookbook
  • Toc
  • feedback
Salt Cookbook

Salt Cookbook

By : Anirban Saha
3.5 (2)
close
Salt Cookbook

Salt Cookbook

3.5 (2)
By: Anirban Saha

Overview of this book

If you are a professional associated with system and infrastructure management, looking at automated infrastructure and deployments, then this book is for you. No prior experience of Salt is required.
Table of Contents (13 chapters)
close
12
Index

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.

  1. Create a new state in the staging environment named hostconfig by creating a directory called hostconfig in the base directory of the staging environment. Create a directory called files in the hostconfig directory and also a file named init.sls.

  2. 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]...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete