Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

There's more...

In addition to host_vars and group_vars, Ansible supports the definition of variables using other techniques, including the following:

  • Using the vars keyword within the play to specify multiple variables
  • Using vars_files to define variables in a file and having Ansible read these variables from this file while running the playbook
  • Specifying variables at the command line using the --e option

In addition to the user-defined variables that we can specify, Ansible has some default variables that it builds dynamically for its inventory. The following table captures some of the most frequently used variables:

        
 inventory_hostname  The name of the hosts as defined in the inventory (for example, csr1 and mx1)
 play_hosts  A list of all the hosts included in the play
 group_names  A list of all the groups that a specific host is a part of (for example, for csr1 this will be [edge, Cisco, network])