Chapter 3. Separating Code and Data – Variables, Facts, and Templates

In the previous chapter, we looked at how to write a role to provide modularity and abstraction. While doing so, we created the configuration file and copied the file over to the destination host using Ansible's copy module.

In this chapter, we will cover the following concepts:

  • How do you separate data from code?
  • What are Jinja2 templates? How are these created?
  • What are variables? How and where are they used?
  • What are system facts? How are they discovered?
  • What are the different types of variables?
  • What is a variable merge order? What are its precedence rules?

Static content explosion

Let's imagine that we are managing a cluster of hundreds of web servers spanning across multiple data ...

Get Ansible Playbook Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.