Document host_vars option.

This commit is contained in:
Christian Henz 2015-12-01 16:43:03 +01:00
parent dd4ae1a51c
commit 78766ded4e
2 changed files with 46 additions and 0 deletions

View File

@ -31,6 +31,23 @@ Some of these options are for advanced usage only and should not be used unless
```
These variables take the highest precedence over any other variables.
- `host_vars` (hash) - Set of inventory host variables to be included in the [auto-generated inventory file](http://docs.ansible.com/ansible/intro_inventory.html#host-variables).
Example:
```ruby
ansible.host_vars = {
"host1" => {"http_port" => 80,
"maxRequestsPerChild" => 808},
"host2" => {"http_port" => 303,
"maxRequestsPerChild" => 909}
}
```
Notes:
- This option has no effect when the `inventory_path` option is defined.
- `groups` (hash) - Set of inventory groups to be included in the [auto-generated inventory file](/v2/provisioning/ansible_intro.html).
Example:

View File

@ -107,6 +107,35 @@ default ansible_connection=local
Note that the generated inventory file is uploaded to the guest VM in a subdirectory of [`tmp_path`](/v2/provisioning/ansible_local.html), e.g. `/tmp/vagrant-ansible/inventory/vagrant_ansible_local_inventory`.
**Host variables:**
Since Vagrant ???, the [`host_vars`](/v2/provisioning/ansible_common.html) option can be used to set [variables for individual hosts](http://docs.ansible.com/ansible/intro_inventory.html#host-variables) in the generated inventory file (see also the notes on group variables below).
```
Vagrant.configure(2) do |config|
config.vm.define "host1"
config.vm.define "host2"
config.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.host_vars = {
"host1" => {"http_port" => 80,
"maxRequestsPerChild" => 808},
"host2" => {"http_port" => 303,
"maxRequestsPerChild" => 909}
}
end
end
```
Generated inventory:
```
# Generated by Vagrant
host1 ansible_ssh_host=... http_port=80 maxRequestsPerChild=808
host2 ansible_ssh_host=... http_port=303 maxRequestsPerChild=909
```
**How to generate Inventory Groups:**
The [`groups`](/v2/provisioning/ansible_common.html) option can be used to pass a hash of group names and group members to be included in the generated inventory file. It is also possible to specify [group variables](http://docs.ansible.com/ansible/intro_inventory.html#group-variables).