Comments (18)
You should be able to use Cloud Init... It supports setting static IP.
https://github.com/josenk/terraform-provider-esxi/tree/master/examples/05%20CloudInit%20and%20Templates
https://github.com/josenk/terraform-provider-esxi/blob/master/examples/05%20CloudInit%20and%20Templates/main.tf#L14-L23
https://cloudinit.readthedocs.io/en/latest/topics/network-config-format-v2.html
Remote-exec should work if you set the configuration in the files only, then do a delayed reboot. That way terraform can complete it's execution.
from terraform-provider-esxi.
Sorry, It's not built in to the esxi provider. You need to use a provisioner (like salt chef, puppet, remote-exec to set a static IP.
from terraform-provider-esxi.
Hi!
Sorry by reopen this issue, but can you give a example how to set static IP?
I've tried with remote-exec editing the ifcfg file and restaring the network service, but it cause problem in terraform execution.
Thanks by the tool, btw... It saves me!!!
from terraform-provider-esxi.
Nice! I did using cloud-init but runing the commands to edit the in ifcfg file. The network configs doesn't work.. I searched on web and many people had the same problem and solved by using 'sed' linux command.
Thanks for your help and tool!
PS.: the url to install cloud init in your example is wrong, here is the correct command:
yum install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm
from terraform-provider-esxi.
Actually those delay reboot does not solve the issue - I have something like this:
provisioner "local-exec" {
command = "ssh -o 'StrictHostKeyChecking no' -t -i ${var.ssh_rsa_file_path} me@${esxi_guest.docker.ip_address} '(sleep 20s && sudo reboot)& sudo /root/install/network.sh 24'"
}
but the problem is that after changing IP and reboot - provisioner is still reporting that host is creating.... :(
from terraform-provider-esxi.
@replay111 I'd the same problem.. I solve using cloud-init as @josenk indicates, but in userdata.tpl I put sed
commands to edit the ifcfg file as follows:
`runcmd:
- date >/root/cloudinit.log
- sed -i -e 's/BOOTPROTO="none"/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-ens192
- sed -i -E 's/IPADDR=.+"/IPADDR="10.10.1.${IP}"/g' /etc/sysconfig/network-scripts/ifcfg-ens192
- sed -i -E 's/NAME=.+"/NAME="ens36"/g' /etc/sysconfig/network-scripts/ifcfg-ens192
- sed -i -E 's/DEVICE=.+"/DEVICE="ens36"/g' /etc/sysconfig/network-scripts/ifcfg-ens192
- sed -i -E "s/UUID=.+"/UUID="$(uuidgen ens36)"/g" /etc/sysconfig/network-scripts/ifcfg-ens192
- mv /etc/sysconfig/network-scripts/ifcfg-ens192 /etc/sysconfig/network-scripts/ifcfg-ens36
- nmcli con del ens192`
Just to explain, my VM that I use as template has one network interface (ens192) and during installation of the template I set as static IP and put an IP only to have the ifcfg file. When the terraform clones, the VM puts the network id to ens36, because of this I execute the mv
after last sed command and remove the ens192 indicator just to keep the VM clean.
I hope that this helps you!
from terraform-provider-esxi.
While it doesn't work as a generic solution across all OSs, this might be a good wiki article for linux distros.
from terraform-provider-esxi.
Hi I did workaround like this:
provisioner "remote-exec" {
inline = [
"/root/install/hostname.sh docker",
"screen -AmdS delay_ip_change bash",
"screen -S delay_ip_change -p 0 -X stuff $'sleep 20s\n/root/install/network.sh 24\r'"
]
}
but my network.sh script is very simple (this is my test server so no need to have some huge network):
IFACE=`nmcli -t -f device connection show --active | head -1`
IFACE=`echo $IFACE | xargs`
nmcli c modify "$IFACE" ipv4.addresses 192.168.1.$1/24
nmcli c modify "$IFACE" ipv4.gateway 192.168.1.1
nmcli c modify "$IFACE" ipv4.dns 192.168.1.1
nmcli c modify "$IFACE" ipv4.method manual
nmcli c down "$IFACE" ; nmcli c up "$IFACE"
nmcli d show "$IFACE"
from terraform-provider-esxi.
Hi I did workaround like this:
provisioner "remote-exec" { inline = [ "/root/install/hostname.sh docker", "screen -AmdS delay_ip_change bash", "screen -S delay_ip_change -p 0 -X stuff $'sleep 20s\n/root/install/network.sh 24\r'" ] }
but my network.sh script is very simple (this is my test server so no need to have some huge network):
IFACE=`nmcli -t -f device connection show --active | head -1` IFACE=`echo $IFACE | xargs` nmcli c modify "$IFACE" ipv4.addresses 192.168.1.$1/24 nmcli c modify "$IFACE" ipv4.gateway 192.168.1.1 nmcli c modify "$IFACE" ipv4.dns 192.168.1.1 nmcli c modify "$IFACE" ipv4.method manual nmcli c down "$IFACE" ; nmcli c up "$IFACE" nmcli d show "$IFACE"
Nice! I'll try this because my VM will be with 2 network interfaces and your script looks better then my.
I did like to use cloud-init because the script is executed after the terraform finish, so it is faster and his provision became modular.
Thanks for share!
from terraform-provider-esxi.
Post working solutions here if you like... I will add additional solutions when time permits.
from terraform-provider-esxi.
Hi,
the problem is that I do not want to rely on DHCP server especially for machines that are created dynamically, so better option for me is to apply static IP after machine is build and then remove it along with destroying the machine.
from terraform-provider-esxi.
Hi,
the problem is that I do not want to rely on DHCP server especially for machines that are created dynamically, so better option for me is to apply static IP after machine is build and then remove it along with destroying the machine.
Ohhh.. I get it! I have the same problem. But using cloud-init, the Terraform finishs his job before the VM startup. It only power on the VM and finish.. When VM starts up the cloud-init is executed and apply my static IP and another configs..
Unless that you need the given IP into Terraform. Is this your case?
from terraform-provider-esxi.
Post working solutions here if you like... I will add additional solutions when time permits.
Nice! I'll do this!
from terraform-provider-esxi.
I am not using cloud-init (I am not familiar with it, does it works with ESXi?). My purpose is to have fully configured machine with static IP when terraform end its work. When terraform finish its job ansible job will be started to probision machine.
from terraform-provider-esxi.
I am not using cloud-init (I am not familiar with it, does it works with ESXi?). My purpose is to have fully configured machine with static IP when terraform end its work. When terraform finish its job ansible job will be started to probision machine.
I'll put my solution on https://github.com/josenk/terraform-provider-esxi-wiki as @josenk suggests to you see how it works... Can you do too? I'd like to see your full solution!
from terraform-provider-esxi.
Sure - I will prepare my repo with it - but this is really really simple - for now 2 hosts infra - I am just starting to learn this kind of thing, so nothing spectacular :D
from terraform-provider-esxi.
https://github.com/replay111/tf-esxi-test - you can look here. I also changed a little bit approach and I am not using screen anymore - I am just setting on_failure = continue
flag and it works perfect for me.
from terraform-provider-esxi.
Using http(s) sources was added in the 1.6.1 release.
Version History
- 1.6.1 Fix some minor refesh bugs, allow http(s) ovf sources.
from terraform-provider-esxi.
Related Issues (20)
- terraform-provider-esxi_v1.10.2 - terrafom apply bug esxi 7.0 Update 3 panic: runtime error: invalid memory address or nil pointer dereference HOT 3
- guest resource should be able to reserve memory HOT 1
- The OS is not set for windows vm, I have given guestos as Windows, when the vm is created it shows as Other in os field HOT 2
- Help with disks HOT 1
- Some guest resources are planned to be recreated because of guestinfo HOT 4
- Error: The terraform-provider-esxi_v1.10.0 plugin crashed! HOT 13
- FEATURE: also allow per-host connection details in resource config HOT 3
- Newbie - clone_from_vm or guestinfo doc HOT 2
- Support for arbitrary ISO file installation to create an Android VM HOT 1
- Question about "clone_from_vm" HOT 1
- Ovftool error while using ovf_source ( Terraform) HOT 2
- │ Error: No network mapping specified. OVF networks: Bridged NAT. Target networks: VM Network VM Network2 HOT 3
- ReadMe identifies a breaking change at version 1.9.0 HOT 2
- esxi_guest sub directory HOT 1
- VM's only get an IP address by using cloudinit HOT 1
- Plugin did not respond HOT 4
- Running example 8th, the VM network is not being set up. HOT 2
- Not able to login in this customized case HOT 2
- clone_from_vm brings the source VM from esxi host to local then back to esxi host HOT 1
- SSH key auth for connect to esxi HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-esxi.