From 78766ded4e60ccada7d2e6f65923d7e00f3b9063 Mon Sep 17 00:00:00 2001 From: Christian Henz Date: Tue, 1 Dec 2015 16:43:03 +0100 Subject: [PATCH] Document host_vars option. --- .../v2/provisioning/ansible_common.html.md | 17 +++++++++++ .../v2/provisioning/ansible_intro.html.md | 29 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/website/docs/source/v2/provisioning/ansible_common.html.md b/website/docs/source/v2/provisioning/ansible_common.html.md index 053938d5c..44b787e7e 100644 --- a/website/docs/source/v2/provisioning/ansible_common.html.md +++ b/website/docs/source/v2/provisioning/ansible_common.html.md @@ -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: diff --git a/website/docs/source/v2/provisioning/ansible_intro.html.md b/website/docs/source/v2/provisioning/ansible_intro.html.md index 6bbb377b9..441e8cbc8 100644 --- a/website/docs/source/v2/provisioning/ansible_intro.html.md +++ b/website/docs/source/v2/provisioning/ansible_intro.html.md @@ -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).