force Static IP on VM creation - ansible

I have an ansible script that connects to my Vcenter and builds out a VM. This works great assuming the network it will be built on has DHCP enabled. I am building mostly Centos 7 VM's on a network that does not have DHCP enabled meaning static IP's. The VM gets built, but then I am stuck logging into each VM manually and assigning the IP.
How can I tell CentOS to use a specific IP?
I am familiar with kickstart, but not sure how to trigger the install to pickup a ks file. (I know I can create a custom ISO, but I dont want to create a custom ISO for each VM I built.)
I have tried using the following flags on ansible VMware_guest module, but no luck.
Any Suggestions??
vmware_guest:
network:
type: static
ip: 192.168.1.5
mask: 255.255.255.0
gateway: 192.168.1.1

Please try using netmask instead of mask.
vmware_guest:
network:
name: "{{ network_name }}"
type: static
ip: 192.168.1.5
netmask: 255.255.255.0
gateway: 192.168.1.1

Related

disable public ip of GCE vm in ansible playbook

I have ansible playbook for for GCE VM creation. This playbook launch GCE VM with public ip address.
How to launch my GCE vm without public ip address.?
I'm new to ansible.
I suppose you are using GCE Ansisble module for VM creation. According to GCE module documentation, the module has a parameter named external_ip. Set it to none if you don't want any public IP address assigned to your VM.
external_ip:
type of external ip, ephemeral by default; alternatively, a fixed gce ip or ip name can be given. Specify 'none' if no external ip is desired.
Example:
- gce:
instance_names: my-test-instance1
zone: us-central1-a
machine_type: n1-standard-1
external_ip: none
image: debian-8
state: present
service_account_email: "your-sa#your-project-name.iam.gserviceaccount.com"
credentials_file: "/path/to/your-key.json"
project_id: "your-project-name"
disk_size: 32

How to browse to Vagrant VM site from other devices on local network?

I'm running Laravel Homestead (Vagrant) on Windows 10.
I'd like to be able to use other devices on my LAN to test my Homestead site too. (My LAN also has a Mac and an iPhone.)
I found two ancient questions (1 and 2) that seem related to my goal, but I'm still stuck.
I've tried adding a public_network config to my Homestead.yaml according to the docs (https://laravel.com/docs/5.4/homestead#network-interfaces).
I've tried editing the homestead.rb file directly, too (but that didn't seem to help, so I reverted it).
My Homestead.yaml is:
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa2013
folders:
- map: c:/code/katievb-members
to: /home/vagrant/Code/katievb-members
sites:
- map: kvbmem.rcw
to: /home/vagrant/Code/katievb-members/public
schedule: false
databases:
- kvbmem
networks:
- type: "public_network"
ip: "192.168.1.104"
bridge: "Realtek RTL8811 Wireless LAN 802.11ac USB 2 Network Adapter"
My Windows machine is 192.168.1.104 on my LAN.
What should I change about my setup so that my Homestead website is browsable not just from the Windows machine that its on but also the other devices on the LAN?
And then what commands should I run before trying to browse to that site (http://kvbmem.rcw) on my iPhone? vagrant reload --provision?
(I have a DD-WRT router with DNSmasq if that will be helpful.)
The question you pointed gave you good hints so you need to enable bridge connection, in vagrant its public_network
If you want to assign a static IP, you cannot use the same IP of your windows machine, otherwise the other machine from your LAN will hit the servers running on the windows machine.
You want to select an IP reachable on your LAN in the same network of your windows machine so if your current IP is 192.168.1.104 you can use any of the 192.168.1.x that is available, for example
networks:
- type: "public_network"
ip: "192.168.1.100"
bridge: "Realtek RTL8811 Wireless LAN 802.11ac USB 2 Network Adapter"

Other computer on the same intranet can't connect to my web server on my virtual machine

I used vagrant to setup a virtual machine and then on that virtual machine, I set up a webserver with ip I config like below:
config.vm.network "private_network", ip: "192.168.33.12"
config.vm.network "public_network", ip: "192.168.33.13"
config.vm.network :public_network
And I connected successfully to my web server on my computer via this IP 192.168.33.12 but then I tried to use other computer on the same network, I couldn't connect to it (192.168.33.13 neither)
It's because your virtual machine missed default gateway for your network.
Try adding your LAN default gateway to the virtual machine.
ssh -p 2222 vagrant#localhost
sudo route add default gw 192.168.33.254
where 192.168.33.254 has to be change with correct default gateway.

How to bind external ip to Vagrant VM?

I have external IP address. I added it to my eth0 interface of host machine. I can successfully ping it. I want to run VM using Vagrant and set my external IP to it (I want to call my VM just like a simple VPS using this external IP address). I have next line in Vagrantfile for this:
node.vm.network "public_network", ip: myExternalIP
After my machine start I see eth2 interface inside my VM with my external IP as inet addr. But I can't get access to any open port on my vm using this IP address. Maybe I don't understand idea of public_network in Vagrant. How to bind external ip to my Vagrant VM?
Update: As I understood vagrant set default gateway of VM to interface under NAT. Due to NAT packages cant be sent from VM to external world through bridged interface.
I got it working this way:
config.vm.network "public_network", ip: "192.168.0.17"

How can I access a vagrant guest from another virtualbox guest?

The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.
The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080
Which address should I be using for the browser testing vm?
The testing vm's default gateway?
The vagrant vm's ip?
The host's virtual network ip?
And should I be using a NAT or host only adapter on the browser testing vm?
That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?
In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).
If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).
Simply add the following code block in your Vagrantfile and do a vagrant reload
Vagrant.configure("2") do |config|
config.vm.network "public_network"
end
You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.
In case you don't want to go with public_network just like me then you should do the steps below using private_network:
Open Vagrantfile from your project root
Search for config.vm.network
Add this line config.vm.network "private_network", ip: "192.168.33.10". Remember this is not the IP of your base machine it's a virtual-box IP address and your machine IP should be different. You can say it's a fake IP address so change it to anything else like 192.168.30.20.
Reload your vagrant using vagrant reload.
Now go to your other virtual guest in my case it's the Windows Guest 2. My base is Linux Mint Vagrant box is on Ubuntu Guest 1. Open C:\Windows\System32\drivers\etc\hosts file as admin and do the above IP's entry in there like 192.168.33.10 local.youralias.com. And save the file, after that you can now browse the site now at http://local.youralias.com/.
In case your guest 2 is also Linux just edit this file sudo vi /etc/hosts, and add this line at top of it 192.168.33.10 local.youralias.com. Now save and exit and browse the URL :)
Enjoy! Happy coding.
Adding to accepted answer, you can actually set IP and specify which network interface to use.
My setup on linux box via wifi and static IP:
You can find your wifi interface name by running ifconfig command.
Vagrant.configure("2") do |config|
config.vm.network "public_network", :bridge => 'wlp8s0', ip: "192.168.1.199"
end
This may have many source cause. In my case, I use vagrant fedora boxe.
I tried:
First using the private_network that I attached to a host only adapter and launched httpd service to test the connection between guest and host
config.vm.network "private_network", type: "dhcp", name: "vboxnet2"
config.vm.network "forwarded_port", guest:80, host:7070
but I was not able to ping my guest machine from the host and could no telnet the httpd service opened
Second using public_network and launched httpd service to test connectivity
config.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)", use_dhcp_assigned_default_route: true
I could ping my guest from my host but I could not telnet the httpd service.
For this two use case, the issue was that the port 80 on the fedora guest host was blocked by the firewall. Here is what fixed the issue and get all working for both privat_network and public_ntwork:
firewall-cmd --permanent --add-port 80/tcp #open the port permanently
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --list-port # list to check if the port was opened
systemctl stop firewalld # stop and open the firewall service
systemctl start firewalld
Old question, new answer: [disclaimer: i am not a vagrant expert]
both solutions might work but the solution in the "vagrant way of thinking" is that some component in your guest (rinetd?) should forward any requests to unknown ports to the host. From the host the request could then be mapped (via vagrant port forwarding) to a services that is running in the other guest.
So, to resume:
1.in guest-1 we do localhost:1234. Guest-1 will detect that this port is not available and forward to host
2. the host will check the vagrant port forwarding and forward to guest-2
3. in guest-2 we have some nice service listening to post 1234
4. done.

Resources