How to define different vars for different hosts in Ansible playbook?

Mvorisek asked:

Is it possible to define different variables for different hosts? like:

- hosts:
      var_a: "xxx"
      var_b: "yyy"
    - some_role

My answer:

Host (and group) variables are not stored in the playbook. They are stored separately, in the inventory file itself, or in files in a directory host_vars or group_vars relative to the inventory file. These files are named after the host or group for which they contain variables.

See Organizing host and group variables in the Ansible documentation for a more complete description of the variable files.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.