I am using Vagrant and Openstack as my provider. I could create successfully create openstack instances using my Vagrant script. I am using
os.floating_ip = :auto
for assigning floating IP address to my machine. How can I get newly created machine info within the same Vagrant script after it has been created. Here I want to get the floating IP address that has been assigned automatically to that machine.
Following is my script
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.synced_folder '.', '/vagrant', disabled: true
config.ssh.private_key_path = "/home/xxxxx"
config.vm.provider :openstack do |os|
os.username = "xxx"
os.api_key = "xxx"
os.flavor = "m1.medium"
os.image = "ubuntu14.04"
os.endpoint = "http://xxx"
os.keypair_name = "xxx"
os.floating_ip = :auto
os.floating_ip_pool = "xxx"
os.ssh_username = "ubuntu"
os.network = "xxx"
os.server_name = "TestInstant"
end
end
I guess you mean to get the information from the host so the most simple is probably to run vagrant ssh-config
, this gives you ssh related information including the host name:
Host default
HostName 172.16.42.206
If you want to get this information while you boot the machine, you can add a shell provisioner:
config.vm.provision "shell", inline: "hostname", run: "always"
config.vm.provision "shell", inline: "ip addr show", run: "always"
you will get those information
==> default: Running provisioner: shell...
default: Running: inline script
==> default: stdin: is not a tty
==> default: precise32
==> default: Running provisioner: shell...
default: Running: inline script
==> default: stdin: is not a tty
==> default: 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
==> default: link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
==> default: inet 127.0.0.1/8 scope host lo
==> default: inet6 ::1/128 scope host
==> default: valid_lft forever preferred_lft forever
==> default: 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
==> default: link/ether 08:00:27:12:96:98 brd ff:ff:ff:ff:ff:ff
==> default: inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
==> default: inet6 fe80::a00:27ff:fe12:9698/64 scope link
==> default: valid_lft forever preferred_lft forever
Obviously you can run simple command or run a script (read more on shell provisioner if needed) to get the information you need