Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't set static IP address in vsphere_virtual_machine #228

Closed
mas9612 opened this issue Oct 31, 2017 · 4 comments
Closed

Can't set static IP address in vsphere_virtual_machine #228

mas9612 opened this issue Oct 31, 2017 · 4 comments
Labels
bug Type: Bug

Comments

@mas9612
Copy link

mas9612 commented Oct 31, 2017

Hello,

I'm using Terraform and vSphere provider to create virtual machine on ESXi.

I want to set static IP address to created machine, but it seems that my config is not working.
Please help me!

Used VM Template

  • CentOS 7
  • VMWare Tools is installed ( yum install open-vm-tools )

(I'm new to Terraform, I'm sorry if I missed past issue related this problem)

Terraform Version

Terraform v0.10.8

vSphere Provider Version

v0.4.2

Affected Resource(s)

  • vsphere_virtual_machine

Terraform Configuration Files

variable "vsphere_user" {}
variable "vsphere_server" {}
variable "vsphere_password" {}
variable "resource_pool" {}

variable "machine_name" {
  default = "dns"
}

variable "template_name" {
  default = "centos7"
}

provider "vsphere" {
  user           = "${var.vsphere_user}"
  password       = "${var.vsphere_password}"
  vsphere_server = "${var.vsphere_server}"

  allow_unverified_ssl = true
}

resource "vsphere_virtual_machine" "dns" {
  name          = "${var.machine_name}"
  vcpu          = 1
  memory        = 2048
  datacenter    = "Bachelor"
  resource_pool = "${var.resource_pool}"
  time_zone     = "Asia/Tokyo"
  dns_servers   = ["10.1.3.21", "10.1.3.80"]

  network_interface {
    label              = "VM Network"
    ipv4_address       = "10.1.240.123"
    ipv4_prefix_length = "16"
    ipv4_gateway       = "10.1.3.1"
  }

  disk {
    template  = "${var.template_name}"
    datastore = "Datastore_"
  }
}

Expected Behavior

Created VM IP address is set to 10.1.240.123 (as same as I set in tf)
Similarly, in terraform.tfstate, network_interface.0.ipv4_address will be set to 10.1.240.123

terraform.tfstate

...
                            "network_interface.0.ipv4_address": "10.1.240.123",
...

Actual Behavior

VM IP address is different in tf (it seems address is served by DHCP)

terraform.tfstate

...
                            "network_interface.0.ipv4_address": "10.1.5.118",
...

Steps to Reproduce

  1. Create and prepare VM template.
  2. Prepare tf file and fill variables with appropriate values.
  3. terraform apply
@vancluever
Copy link
Contributor

Hey @mas9612, sorry for the delay in getting back to you.

To help troubleshoot customization issues, you can check the following file: /var/log/vmware-imc/toolsDeployPkg.txt. This should give you the information necessary to troubleshoot the problem, which is usually due to how the template has been created. Another troubleshooting measure would be to attempt to clone and customize based off of this template outside of TF.

Thanks!

@mas9612
Copy link
Author

mas9612 commented Nov 13, 2017

@vancluever

Thank you,
And I'm sorry for late response.

I checked /var/log/vmware-imc/toolsDeployPkg.txt , I can see debug log in that file like below (picked up only related networking).

DEBUG: opening file /etc/sysconfig/network.
INFO: OLD HOST NAME =
INFO: Customizing Network settings ...
INFO: Erasing DHCP leases
DEBUG: Command: pkill dhclient
DEBUG: Result:
DEBUG: Command: rm -f /var/lib/dhcp/*
DEBUG: Result:
INFO: Resetting Network Administration Tool (redhat-config-network)
DEBUG: Command: rm -rf /etc/sysconfig/networking/devices
DEBUG: Result:
DEBUG: Command: rm -rf /etc/sysconfig/networking/profiles
DEBUG: Result:
DEBUG: opening file /etc/sysconfig/network.
DEBUG: Line : # Created by anaconda

DEBUG: opening file for writing (/etc/sysconfig/network).
DEBUG: Command: chmod 644 /etc/sysconfig/network
DEBUG: Result:
DEBUG: Command: hostname k800123-ir-web-1
DEBUG: Result:
INFO: Customizing NICS ...
DEBUG: Command: modprobe pcnet32 2> /dev/null
DEBUG: Result:
DEBUG: Command: /sbin/ifconfig eth0 2> /dev/null
DEBUG: Result:
INFO: Customizing NICS. { NIC1 }
INFO: Customizing NIC NIC1
DEBUG: Command: /sbin/ifconfig -a
DEBUG: Result: ens160: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:56:b9:8e:46  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 80  bytes 6800 (6.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 6800 (6.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


DEBUG: Command: /sbin/ifconfig -a
DEBUG: Result: ens160: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:56:b9:8e:46  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 80  bytes 6800 (6.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 6800 (6.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

INFO: NIC suffix = ether
INFO: Query config for ^(NIC1\|IPv6ADDR\|)
INFO: Query config for ^(NIC1\|IPv6NETMASK\|)
DEBUG: opening file for writing (/etc/sysconfig/network-scripts/ifcfg-ether).
DEBUG: Command: chmod 644 /etc/sysconfig/network-scripts/ifcfg-ether
DEBUG: Result:
INFO: Query config for ^NIC1(\|IPv6GATEWAY\|)
INFO: Configuring route (gateway settings) for ether.
INFO: Configuring route 10.1.3.1
DEBUG: opening file for writing (/etc/sysconfig/network-scripts/route-ether).
DEBUG: opening file for writing (/etc/sysconfig/network-scripts/route6-ether).
INFO: Customizing Hosts file ...
DEBUG: Old hostname=[localhost.localdomain]
DEBUG: Old FQDN=[localhost]
DEBUG: New hostname=[k800123-ir-web-1]
DEBUG: New FQDN=[k800123-ir-web-1.vsphere.local]
DEBUG: opening file /etc/hosts.
DEBUG: Line (inp): 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

DEBUG: Line (inp): ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

DEBUG: Static ip entry added
DEBUG: Line (out): 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

DEBUG: Line (out):
10.1.240.123    k800123-ir-web-1.vsphere.local k800123-ir-web-1

DEBUG: opening file for writing (/etc/hosts).
DEBUG: Command: chmod 644 /etc/hosts
DEBUG: Result:
INFO: Customizing DNS ...
DEBUG: opening file /etc/nsswitch.conf.
DEBUG: opening file for writing (/etc/nsswitch.conf).
DEBUG: Command: chmod 644 /etc/nsswitch.conf
DEBUG: Result:
INFO: Query config for ^(DNS\|SUFFIX\|)
DEBUG: Match Found : DNS|SUFFIX|1
DEBUG: 0
INFO: Query config for ^(DNS\|NAMESERVER\|)
DEBUG: Match Found : DNS|NAMESERVER|1
DEBUG: 0
DEBUG: Match Found : DNS|NAMESERVER|2
DEBUG: 1
DEBUG: opening file for writing (/etc/resolv.conf).
DEBUG: Command: chmod 644 /etc/resolv.conf
DEBUG: Result:
DEBUG: Command: /sbin/ifconfig -a
DEBUG: Result: ens160: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:50:56:b9:8e:46  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 80  bytes 6800 (6.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 80  bytes 6800 (6.6 KiB)


INFO: Query config for ^(DNS\|SUFFIX\|)
DEBUG: Match Found : DNS|SUFFIX|1
DEBUG: 0
DEBUG: opening file for writing (/etc/dhclient-ether.conf).
DEBUG: Command: chmod 644 /etc/dhclient-ether.conf
DEBUG: Result:
INFO: Query config for ^(DNS\|NAMESERVER\|)
DEBUG: Match Found : DNS|NAMESERVER|1
DEBUG: 0
DEBUG: Match Found : DNS|NAMESERVER|2
DEBUG: 1
DEBUG: opening file for writing (/etc/dhclient-ether.conf).
DEBUG: Command: chmod 644 /etc/dhclient-ether.conf
DEBUG: Result:
INFO: Customizing Date&Time ...
DEBUG: opening file /tmp/.vmware/linux/deploy/scripts/tzdata/backward.
DEBUG: Command: ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
DEBUG: Result:
DEBUG: opening file for writing (/etc/sysconfig/clock).
DEBUG: Command: chmod 644 /etc/sysconfig/clock
DEBUG: Result:
DEBUG: opening file for writing (/etc/sysconfig/clock).
DEBUG: Command: chmod 644 /etc/sysconfig/clock
DEBUG: Result:
INFO: Customization completed.

It seems that network configuration by VMWare Tools is working (I think).
But I can't determine this problem is occured by my misconfiguration or any other reason.

I'll continue to investigate this issue.

Thank you,

@vancluever
Copy link
Contributor

Thanks @mas9612,

We have a new version of the resource going in that makes customization a lot more explicit and might help with this.

Also, if you are still having issues, you might want to check for CentOS related issues on open-vm-tools and see if any of those match the problem you are experiencing.

If you have any updates let me know!

@radeksimko radeksimko added the bug Type: Bug label Feb 28, 2018
@bill-rich
Copy link
Contributor

This is likely resolved with the new virtual_machine resource. If you're still experiencing this issue, please open a new issue with the details from the current resource. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Apr 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Type: Bug
Projects
None yet
Development

No branches or pull requests

4 participants