Merge pull request #2606 from maspwr/ansible-groups
Add ability to use Ansible groups in generated inventory. Fixes #2551.
This commit is contained in:
commit
213534d185
|
@ -12,6 +12,7 @@ module VagrantPlugins
|
||||||
attr_accessor :tags
|
attr_accessor :tags
|
||||||
attr_accessor :skip_tags
|
attr_accessor :skip_tags
|
||||||
attr_accessor :start_at_task
|
attr_accessor :start_at_task
|
||||||
|
attr_accessor :groups
|
||||||
attr_accessor :host_key_checking
|
attr_accessor :host_key_checking
|
||||||
|
|
||||||
# Joker attribute, used to pass unsupported arguments to ansible anyway
|
# Joker attribute, used to pass unsupported arguments to ansible anyway
|
||||||
|
@ -30,6 +31,7 @@ module VagrantPlugins
|
||||||
@skip_tags = UNSET_VALUE
|
@skip_tags = UNSET_VALUE
|
||||||
@start_at_task = UNSET_VALUE
|
@start_at_task = UNSET_VALUE
|
||||||
@raw_arguments = UNSET_VALUE
|
@raw_arguments = UNSET_VALUE
|
||||||
|
@groups = UNSET_VALUE
|
||||||
@host_key_checking = "true"
|
@host_key_checking = "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ module VagrantPlugins
|
||||||
@skip_tags = nil if @skip_tags == UNSET_VALUE
|
@skip_tags = nil if @skip_tags == UNSET_VALUE
|
||||||
@start_at_task = nil if @start_at_task == UNSET_VALUE
|
@start_at_task = nil if @start_at_task == UNSET_VALUE
|
||||||
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
@raw_arguments = nil if @raw_arguments == UNSET_VALUE
|
||||||
|
@groups = {} if @groups == UNSET_VALUE
|
||||||
@host_key_checking = nil if @host_key_checking == UNSET_VALUE
|
@host_key_checking = nil if @host_key_checking == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,31 @@ module VagrantPlugins
|
||||||
generated_inventory_file.open('w') do |file|
|
generated_inventory_file.open('w') do |file|
|
||||||
file.write("# Generated by Vagrant\n\n")
|
file.write("# Generated by Vagrant\n\n")
|
||||||
file.write("#{machine.name} ansible_ssh_host=#{ssh[:host]} ansible_ssh_port=#{ssh[:port]}\n")
|
file.write("#{machine.name} ansible_ssh_host=#{ssh[:host]} ansible_ssh_port=#{ssh[:port]}\n")
|
||||||
|
|
||||||
|
# Write out groups information. Only include current
|
||||||
|
# machine and its groups to avoid Ansible errors on
|
||||||
|
# provisioning.
|
||||||
|
groups_of_groups = {}
|
||||||
|
included_groups = []
|
||||||
|
|
||||||
|
config.groups.each_pair do |gname, gmembers|
|
||||||
|
if gname.end_with?(":children")
|
||||||
|
groups_of_groups[gname] = gmembers
|
||||||
|
elsif gmembers.include?("#{machine.name}")
|
||||||
|
included_groups << gname
|
||||||
|
file.write("\n[#{gname}]\n")
|
||||||
|
file.write("#{machine.name}\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
groups_of_groups.each_pair do |gname, gmembers|
|
||||||
|
unless (included_groups & gmembers).empty?
|
||||||
|
file.write("\n[#{gname}]\n")
|
||||||
|
gmembers.each do |gm|
|
||||||
|
file.write("#{gm}\n") if included_groups.include?(gm)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return generated_inventory_file.to_s
|
return generated_inventory_file.to_s
|
||||||
|
|
|
@ -146,4 +146,13 @@ by the sudo command.
|
||||||
* `ansible.raw_arguments` is an *unsafe wildcard* string that can be used to take advantage of `ansible-playbook` arguments that are not (yet) supported by this Vagrant provisioner plugin. This can be very useful when integrating with bleeding edge Ansible versions. Following precedence rules apply:
|
* `ansible.raw_arguments` is an *unsafe wildcard* string that can be used to take advantage of `ansible-playbook` arguments that are not (yet) supported by this Vagrant provisioner plugin. This can be very useful when integrating with bleeding edge Ansible versions. Following precedence rules apply:
|
||||||
* Any supported options (described above) will override conflicting `raw_arguments` value (e.g. `--tags` or `--start-at-task`)
|
* Any supported options (described above) will override conflicting `raw_arguments` value (e.g. `--tags` or `--start-at-task`)
|
||||||
* Vagrant default user authentication can be overridden via `raw_arguments` (with custom values for `--user` and `--private-key`)
|
* Vagrant default user authentication can be overridden via `raw_arguments` (with custom values for `--user` and `--private-key`)
|
||||||
|
* `ansible.groups` can be used to pass a hash of group names and group members to be included in the generated inventory file. For example:
|
||||||
|
```
|
||||||
|
ansible.groups = {
|
||||||
|
"group1" => ["machine1"],
|
||||||
|
"group2" => ["machine2", "machine3"],
|
||||||
|
"all_groups:children" => ["group1", "group2"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Note that only the current machine and its related groups will be added to the inventory file.
|
||||||
* `ansible.host_key_checking` can be set to `false` which will disable host key checking and prevent `"FAILED: (25, 'Inappropriate ioctl for device')"` errors from being reported during provisioner runs. The default value is `true`, which matches the default behavior of Ansible 1.2.1 and later.
|
* `ansible.host_key_checking` can be set to `false` which will disable host key checking and prevent `"FAILED: (25, 'Inappropriate ioctl for device')"` errors from being reported during provisioner runs. The default value is `true`, which matches the default behavior of Ansible 1.2.1 and later.
|
||||||
|
|
Loading…
Reference in New Issue