GithubHelp home page GithubHelp logo

Comments (18)

josenk avatar josenk commented on August 17, 2024 1

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.

josenk avatar josenk commented on August 17, 2024

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.

https://www.terraform.io/docs/provisioners/

from terraform-provider-esxi.

jremerich avatar jremerich commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

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.

replay111 avatar replay111 commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

@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.

silasb avatar silasb commented on August 17, 2024

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.

replay111 avatar replay111 commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

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.

josenk avatar josenk commented on August 17, 2024

Post working solutions here if you like... I will add additional solutions when time permits.

https://github.com/josenk/terraform-provider-esxi-wiki

from terraform-provider-esxi.

replay111 avatar replay111 commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

Post working solutions here if you like... I will add additional solutions when time permits.

https://github.com/josenk/terraform-provider-esxi-wiki

Nice! I'll do this!

from terraform-provider-esxi.

replay111 avatar replay111 commented on August 17, 2024

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.

jremerich avatar jremerich commented on August 17, 2024

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.

replay111 avatar replay111 commented on August 17, 2024

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.

replay111 avatar replay111 commented on August 17, 2024

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.

josenk avatar josenk commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.