Vagrant fails to associate the correct custom Azure NSG with the new VM. In my Vagrant file I assigned the nsg_name key the value for the NSG name from my list of VMs but Azure VM created does not have that NSG but uses the default NSG.
subnet_1 = "Subnet_1"
subnet_2 = "Subnet_2"
subnet_3 = "Subnet_3"
#sg_web = "OfferingRSVagERG-nsg"
#sg_ssh = "OfferingRSVagERG-nsg"
sg_web = "Dojo_Web_NSG"
sg_ssh = "Dojo_SSH_NSG"
nodes = [
{ :hostname => 'dojo-control-4', :ip => '192.166.1.20', :sg => sg_ssh, :subnet => subnet_1},
{ :hostname => 'dojo-lb-4', :ip => '192.166.1.30', :sg => sg_web, :subnet => subnet_1},
{ :hostname => 'dojo-app01-4', :ip => '192.166.2.10', :sg => sg_web, :subnet => subnet_2},
{ :hostname => 'dojo-app02-4', :ip => '192.166.2.11', :sg => sg_web, :subnet => subnet_2},
{ :hostname => 'dojo-db01-4', :ip => '192.166.3.10', :sg => sg_ssh, :subnet => subnet_3},
]
Vagrant.configure("2") do |config|
nodes.each do |node|
config.vm.define node[:hostname] do |nodeconfig|
nodeconfig.vm.box = "azure"
dir = File.expand_path("..", __FILE__)
puts "DIR: #{dir}"
nodeconfig.ssh.private_key_path = "~/.ssh/id_rsa"
nodeconfig.vm.provider :azure do |azure, override|
nodeconfig.vm.synced_folder ".", "/vagrant", disabled: true
# each of below values will default to use the env vars if not specified explicitly.
azure.tenant_id = '0362a91e-ece5-48f5-8820-ad8d63ab4aab'
azure.client_id = 'fc59863a-3195-407f-989e-8f449222fdca'
azure.client_secret = 'zW4zDjvqa41oS+0EMOP/b+-XqItsiDok'
azure.subscription_id = '2b30ee77-2f35-4f2c-a111-65152dace793'
# ^^^^ Above all needed to authenticate and authorize to use Azure resources
azure.resource_group_name='GSAOffering-TFRG'
azure.location='eastus'
azure.instance_ready_timeout = 600
azure.admin_username="Rahul.Srivastava@DevSecOpsPerspecta.onmicrosoft.com"
azure.vm_name=node[:hostname]
azure.vm_image_urn='OpenLogic:CentOS:7.5:latest'
virtual_network_name='GSAOffering_TFVN'
# azure.keypair_name = "demo-workstation" - Does not exist for azure
override.ssh.username = "centos"
nsg_name = node[ :sg ]
subnet_name = node[ :subnet ]
end
end
config.vm.provision "file", source: "../../../ansible", destination: "./ansible"
config.vm.provision "file", source: "../../../ansible/demo/playbooks/files/azure/config", destination: "/.ssh/config"
config.vm.provision "file", source: "/.ssh/id_rsa", destination: "/.ssh/id_rsa"
config.vm.provision "file", source: "/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub"
config.vm.provision "shell" do |s|
s.inline = <<-SHELL
echo ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 /home/centos/.ssh/*
chown centos:centos /home/centos/.ssh/*
SHELL
end
end
end
Vagrant fails to associate the correct custom Azure NSG with the new VM. In my Vagrant file I assigned the nsg_name key the value for the NSG name from my list of VMs but Azure VM created does not have that NSG but uses the default NSG.
subnet_1 = "Subnet_1"
subnet_2 = "Subnet_2"
subnet_3 = "Subnet_3"
#sg_web = "OfferingRSVagERG-nsg"
#sg_ssh = "OfferingRSVagERG-nsg"
sg_web = "Dojo_Web_NSG"
sg_ssh = "Dojo_SSH_NSG"
nodes = [
{ :hostname => 'dojo-control-4', :ip => '192.166.1.20', :sg => sg_ssh, :subnet => subnet_1},
{ :hostname => 'dojo-lb-4', :ip => '192.166.1.30', :sg => sg_web, :subnet => subnet_1},
{ :hostname => 'dojo-app01-4', :ip => '192.166.2.10', :sg => sg_web, :subnet => subnet_2},
{ :hostname => 'dojo-app02-4', :ip => '192.166.2.11', :sg => sg_web, :subnet => subnet_2},
{ :hostname => 'dojo-db01-4', :ip => '192.166.3.10', :sg => sg_ssh, :subnet => subnet_3},
]
Vagrant.configure("2") do |config|
nodes.each do |node|
config.vm.define node[:hostname] do |nodeconfig|
config.vm.provision "file", source: "../../../ansible", destination: "./ansible"
config.vm.provision "file", source: "../../../ansible/demo/playbooks/files/azure/config", destination: "
/.ssh/config"/.ssh/id_rsa", destination: "config.vm.provision "file", source: "
/.ssh/id_rsa"/.ssh/id_rsa.pub", destination: "~/.ssh/id_rsa.pub"config.vm.provision "file", source: "
config.vm.provision "shell" do |s|
s.inline = <<-SHELL
echo ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 /home/centos/.ssh/*
chown centos:centos /home/centos/.ssh/*
SHELL
end
end
end