2.2.5
Mac OS 10.14.6
Centos 7
VAGRANFILE_API_VERSION = 2
POSTGRESQL_COUNT = 3
Vagrant.configure(VAGRANFILE_API_VERSION) do |config|
# config.vbguest.auto_update = false
config.hostmanager.enabled = true
config.hostmanager.manage_host = false
config.hostmanager.manage_guest = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
# Disable NAT DNS
# https://serverfault.com/questions/453185/vagrant-virtualbox-dns-10-0-2-3-not-working
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
(1..POSTGRESQL_COUNT).each do |n|
config.vm.define "server#{n}" do |define|
define.vm.box = "centos/7"
define.ssh.insert_key = false
define.vm.hostname = "server#{n}"
define.vm.network :private_network, ip: "10.0.15.10#{n}"
define.vm.provider "virtualbox" do |node|
node.name = "server#{n}"
end
if n == POSTGRESQL_COUNT
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provision_patroni.yml"
ansible.limit = "all"
ansible.groups = {
"patroni" => ["server[1:#{POSTGRESQL_COUNT}]"],
"vagrant:vars" => {
"k8s_environment" => "vagrant"
},
"vagrant:children" => ["patroni"]
}
ansible.extra_vars = "inventory/group_vars/vagrant.yml"
end
end
end
end
end
Ansible playbook should be executed once all VMs are up
Ansible playbook is executed for each VM separately
Run vagrant up with provided Vangratfile
Hey there @mazay - The behavior you described is working as expected. The provisioners for a given guest will always run during the guest setup, and does not run separately after each guest has finished being created. Today, you might be able to accomplish your desired behavior with Command Triggers, but at the moment there is no built in support to run a guests provisioners step after all guests have been brought up like you described. Thanks!
Thanks for the prompt reply @briancain but I'm a bit confused because documentation still contains this, which is exactly what I'm trying to use and it's working with 2.2.4 but not with 2.2.5.
I see @mazay - That seems to be a workaround, since ansible can likely run on all guests outside of Vagrants control in a single provision step. Do you have a full --debug log that demonstrates the behavior described? Thanks!
@mazay thank your for the DEBUG logs.
for the 2.2.5 failure, I see a strange user interruption:
Could you please double check this, and maybe provide a new 2.2.5 run example? Thank you :heart:
PLAY [patroni] *****************************************************************
^CDEBUG subprocess: stderr: [ERROR]: User interrupted execution
INFO interface: detail: [ERROR]: User interrupted execution
[ERROR]: User interrupted execution
INFO interface: warn: Waiting for cleanup before exiting...
INFO interface: warn: ==> server3: Waiting for cleanup before exiting...
==> server3: Waiting for cleanup before exiting...
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 31997
DEBUG subprocess: Exit status: 99
ERROR warden: Error occurred: Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
INFO warden: Beginning recovery process...
INFO warden: Recovery complete.
ERROR warden: Error occurred: Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
@gildegoma that's correct, I've interrupted once it started executing the ansible playbook but what's in the log should be enough to see that the execution is started right after server1 was spinned up (for 2.2.5) while for older version ansible starts when all nodes are up. I don't get why do you need to see my ansible output since it's not relevant for the issue.
ok, it turned out that 2.2.5 log is incomplete, I'll re-upload it tomorrow (you were referring to the older version log).
@mazay - You should also try to use define instead of config. config is a top scope Vagrant option, where as the example in the ansible documentation uses the local config option machine. In your case, your locally defined machine config option is called define. So you should change your Vagrantfile to read as:
if n == POSTGRESQL_COUNT
define.vm.provision "ansible" do |ansible|
@mazay - You should also try to use
defineinstead of config.configis a top scope Vagrant option, where as the example in the ansible documentation uses the local config optionmachine. In your case, your locally defined machine config option is calleddefine. So you should change your Vagrantfile to read as:if n == POSTGRESQL_COUNT define.vm.provision "ansible" do |ansible|
will give it a try, thanks
@mazay - You should also try to use
defineinstead of config.configis a top scope Vagrant option, where as the example in the ansible documentation uses the local config optionmachine. In your case, your locally defined machine config option is calleddefine. So you should change your Vagrantfile to read as:if n == POSTGRESQL_COUNT define.vm.provision "ansible" do |ansible|
That fixed the issue, thanks a lot for your help!
@mazay excellent news 👌🏼
@briancain good catch 💜
I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
That fixed the issue, thanks a lot for your help!