Improve simplicity of ansible_local inventory

* Remove separate inventory file and config file
* Define nodes in Vagrantfile
This commit is contained in:
Jon "The Nice Guy" Spriggs 2023-12-05 12:56:09 +00:00 committed by GitHub
parent ac6374cd11
commit 46eb78d33b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -212,30 +212,26 @@ Vagrant.configure("2") do |config|
ansible.verbose = true
ansible.install = true
ansible.limit = "all" # or only "nodes" group, etc.
ansible.inventory_path = "inventory"
ansible.groups = {
"nodes" => ["node1", "node2"],
"localhost" => ["controller"]
}
ansible.host_vars = {
"node1" => {
"ansible_user" => "vagrant",
"ansible_host" => "172.17.177.21",
"ansible_ssh_private_key_file" => "/vagrant/.vagrant/machines/node1/virtualbox/private_key",
"ansible_host_key_checking" => false
},
"node2" => {
"ansible_user" => "vagrant",
"ansible_host" => "172.17.177.22",
"ansible_ssh_private_key_file" => "/vagrant/.vagrant/machines/node2/virtualbox/private_key",
"ansible_host_key_checking" => false
},
}
end
end
end
```
You need to create a static `inventory` file that corresponds to your `Vagrantfile` machine definitions:
```
controller ansible_connection=local
node1 ansible_host=172.17.177.21 ansible_ssh_private_key_file=/vagrant/.vagrant/machines/node1/virtualbox/private_key
node2 ansible_host=172.17.177.22 ansible_ssh_private_key_file=/vagrant/.vagrant/machines/node2/virtualbox/private_key
[nodes]
node[1:2]
```
And finally, you also have to create an [`ansible.cfg` file](https://docs.ansible.com/intro_configuration.html#openssh-specific-settings) to fully disable SSH host key checking. More SSH configurations can be added to the `ssh_args` parameter (e.g. agent forwarding, etc.)
```
[defaults]
host_key_checking = no
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes
```