Defining Ansible variables
Ansible uses variables to store data attributes; they can be at the node, group, or default level. You will define the two most common variable types in this section: host and group variables. It’s important to know that, by default, Ansible expects files in specific directories. In the root of the project, these folders are called host_vars and group_vars, respectively.
Let’s demonstrate how to use host_vars and group_vars to show how you might flexibly store NTP configuration data.
In this recipe, you will enrich the Ansible inventory with the following NTP variable data:
- Set two NTP servers for all hosts to
192.168.1.10and192.168.2.10. - Set just the
client2Linux host to use192.168.2.10and192.168.3.10. - Set the
nokia_srlinuxgroup to use192.168.1.10and192.168.3.10.
To properly set up the variables, you must first create files and a directory structure. The following tree output shows the host_vars...