How to obtain guest ip

1,147 views
Skip to first unread message

James Elmes

unread,
Jun 22, 2017, 11:27:28 AM6/22/17
to Packer
Howdy.

Wondering if there is a way to return the guest IP. I want to initiate a file copy from Shell-Local provisioner, this way the copy is initiated from the local machine running packer.

example: xcopy -source C:\packer\vmtools -destination \\guestip\c$\packer

i have looked everywhere and can't seem to find a way to return the actual guest IP

any help appreciated

James

Rickard von Essen

unread,
Jun 22, 2017, 3:12:14 PM6/22/17
to packe...@googlegroups.com
You can do something like this:

"provisioners": [
  {
    "type": "shell",
    "inline": [ "hostname > /tmp/hostname" ]
  },
  {
    "type": "file",
    "direction": "download",
    "source": "/tmp/hostname",
    "destination": "hostname"
  }
]

And you will get the hostname in the file "hostname".

You just need to switch to ifconfig etc. If you are building in a cloud it might also be possible to use the cli/api if you have an unique name/id/tag etc to lookup. 


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0db28607-448b-4bf7-b2ec-8aa4a72272ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Elmes

unread,
Jun 22, 2017, 10:03:10 PM6/22/17
to Packer
Should have mentioned i am using windows.. 

I know how to copy files to the guest vm, i am trying to initiate the copy from the local windows server i am running packer on. I am doing this manually using the shell-local command

"type": "Shell-Local"
"command": "xcopy -source C:\packer\vmtools -destination \\guestip\c$\packer

The guest IP i am entering manually by checking which dhcp address is allocated to the guest IP from my AD server

Packer knows this address already as it connected over SSH/Winrm without me providing it.. i want to know how i can get it.. using something like {{guest_IP}}

James
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.

Gabo Kete

unread,
Jun 23, 2017, 7:19:29 PM6/23/17
to Packer
I think the guest_ip address is not exported as an environmental variable and only used within the packer code.. what you can do instead is to create a small powershell script to get the guest IP address and use that variable instead

Gabo Kete

unread,
Jun 23, 2017, 7:23:58 PM6/23/17
to Packer
If what you are after ( looking at the piece of JSON file you shared ) is to upload a file from your packer machine to the guest machine , I would recommend you use File provisioner instead ( link below ), which will help you to upload a file without knowing the guest IP address





On Friday, June 23, 2017 at 2:03:10 PM UTC+12, James Elmes wrote:

Rickard von Essen

unread,
Jun 25, 2017, 12:54:05 AM6/25/17
to packe...@googlegroups.com
And if you use the file privisioner with WinRM with larger files you will find that it's slow. The workaround is to use http_directory and environment variable PACKER_HTTP_ADDR, see https://www.packer.io/docs/provisioners/powershell.html#packer_http_addr

To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/7d0a6815-829e-4f30-95cf-bf06688a76db%40googlegroups.com.

James Elmes

unread,
Jun 25, 2017, 6:43:04 PM6/25/17
to packe...@googlegroups.com
that seems like a useful feature add.

To obtain the IP via powershell within the packer script and save it as a variable, any idea the easiest way to do that? i haven't actually done that before.. but is sounds like it should work

regards

James

You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/aEtfUbRz0M4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/0dabf81d-018e-4d8c-a238-cd96dbdcd36d%40googlegroups.com.

James Elmes

unread,
Jun 25, 2017, 6:45:32 PM6/25/17
to packe...@googlegroups.com
the file provisioner uses WINRM and is impossibly slow for big files. I can't use SSH either

Thats why i want to initiate the file copy from the local shell, but require the IP when using the local shell

You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/aEtfUbRz0M4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/7d0a6815-829e-4f30-95cf-bf06688a76db%40googlegroups.com.

James Elmes

unread,
Jun 25, 2017, 6:47:33 PM6/25/17
to packe...@googlegroups.com
Yes i dont't really want to stand up a HTTP server just for this, theres already enough moving parts with automating image creation.. initiating he copy from the local-shell would be perfectly fine if i could reference the guest IP (which packer knows) easily

regards

James

You received this message because you are subscribed to a topic in the Google Groups "Packer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/packer-tool/aEtfUbRz0M4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt8kei779YhPapk7nzmOKRgaRw%2BVKLs_Q3FZ%3DaBXuDyV%3DA%40mail.gmail.com.

Rickard von Essen

unread,
Jun 26, 2017, 12:26:19 AM6/26/17
to packe...@googlegroups.com

James Elmes

unread,
Jun 26, 2017, 1:10:21 AM6/26/17
to packe...@googlegroups.com
I had a read through that issue, thanks for finding that.

Do you know something i can run from shell-local to obtain the IP for guest being built? i am building windows guests from a windows machine..

if i can use obtain the guest ip and use in guest local i can kick off the file transfers i need to much much easier

regards

James

Rickard von Essen

unread,
Jun 26, 2017, 1:19:44 AM6/26/17
to packe...@googlegroups.com
Depends on the builder? Which one are you using?

James Elmes

unread,
Jun 26, 2017, 1:28:00 AM6/26/17
to packe...@googlegroups.com
vmware-iso latest version of packer also

James Elmes

unread,
Jun 26, 2017, 1:28:22 AM6/26/17
to packe...@googlegroups.com

James Elmes

unread,
Jun 29, 2017, 9:07:38 PM6/29/17
to Packer
I guess its not that easy to get the guest IP


Gabo Kete

unread,
Jun 29, 2017, 9:53:43 PM6/29/17
to Packer
sorry not a really expert in Powershell but found this that could help you 


I guess the level of complexity of the powershell script will be up to what you are after.. Bear in mind that packer can execute local and remote scripts.. with different provisioners, probably the most accurate for you is the Powershell provisioner

Reply all
Reply to author
Forward
0 new messages