I am working on a project where I am creating rackspace cloud instances using Vagrant. I am using vagrant-rackspace plugin to do it. Everything works fine for me except the part that I need to capture the IP of the new rackspace instance created in the vagrantfile.
I need this IP address in order to add it to the Ansible inventory file (/etc/ansible/hosts)
Here is my Vagrantfile:
Vagrant.configure(2) do |config|
config.ssh.private_key_path = "rackspace_rsa"
config.vm.provider :rackspace do |rs|
rs.username = "rackspace-user"
rs.api_key = "a98weqrq3r34ewfadsf43rffa4697cc0036"
rs.admin_password = "Password1"
rs.flavor = /1 GB Performance/
rs.image = /Ubuntu 12.04/
rs.rackspace_region = :dfw
rs.server_name = "ansible_server_1"
rs.public_key_path = "rackspace_rsa.pub"
end
end
Once the instance is created I am going to provision the machine using Shell provisioning to install ansible. After installing ansible I will update the inventory file to reflect the IP of the newly created rackspace instance.
You could use the Vagrant Host Manager plugin using the Custom IP Resolver
Custom IP resolver gives you oportunity to calculate IP address for each machine by yourself, giving You also access to the machine that is updating /etc/hosts. For example:
config.hostmanager.ip_resolver = proc do |vm, resolving_vm|
if hostname = (vm.ssh_info && vm.ssh_info[:host])
`host #{hostname}`.split("\n").last[/(\d+\.\d+\.\d+\.\d+)/, 1]
end
end