Sam A.
6e383d6afa
Now that the Vagrantfile supplies SSH port information to Ansible, we no longer need to figure it out in Ansible. Also, since gather_facts (which requires an SSH connection) is set to true in playbook.yml, one needs to supply --extra-vars "ansible_port=22" on the commandline when provisioning for the first time on real hardware, because the port is hardcoded in the inventory file.
38 lines
942 B
Ruby
38 lines
942 B
Ruby
Vagrant.require_version ">= 1.7.0"
|
|
|
|
PORT = 19022
|
|
|
|
Vagrant.configure(2) do |config|
|
|
config.vm.network :forwarded_port, guest: PORT, host: PORT, id: "new_ssh"
|
|
|
|
# If we are trying to SSH into the VM, we need to use the new port
|
|
if ARGV[0] == "ssh"
|
|
config.ssh.guest_port = PORT
|
|
end
|
|
|
|
config.vm.define "datacoop" do |datacoop|
|
|
datacoop.vm.box = "ubuntu/focal64"
|
|
datacoop.vm.hostname = "datacoop"
|
|
|
|
datacoop.vm.provider "virtualbox" do |v|
|
|
v.memory = 4096
|
|
end
|
|
|
|
datacoop.vm.provision "ansible" do |ansible|
|
|
ansible.compatibility_mode = "2.0"
|
|
ansible.playbook = "playbook.yml"
|
|
ansible.ask_vault_pass = true
|
|
ansible.verbose = "v"
|
|
|
|
# If we are running the provision command, then we override the ansible_port
|
|
if ARGV[0] == "provision"
|
|
ansible.host_vars = {
|
|
"datacoop" => {
|
|
"ansible_port" => PORT
|
|
}
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|