Packer - Static Cloud-Init Listener IP

Deployment of a greenfield space with asset of only VMWare cluster + vCenter.

Task is to first build core assets… one of those being VM images (to then deploy initial git-runner into)

But issue is the Packer system when deployment via VPN, just picks first interface of system to deploy from. Vs the Virtual Interface which is “on” the LAN segment and so reachable to pull cloud init during build phase.

Ex:
Remote office/site 172.16.100.x/24
Ignition system IP 172.16.100.146

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:64:bb:0d brd ff:ff:ff:ff:ff:ff
    inet 172.16.100.146/24 brd 172.16.100.255 scope global dynamic noprefixroute eth0
       valid_lft 5429sec preferred_lft 5429sec
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:64:bb:0e brd ff:ff:ff:ff:ff:ff
    inet 169.254.254.101/24 brd 169.254.254.255 scope link noprefixroute eth1
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:1e:67:32:b4 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:1eff:fe67:32b4/64 scope link 
       valid_lft forever preferred_lft forever
6: cscotun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1300 qdisc fq_codel state UNKNOWN group default qlen 500
    link/none 
    inet 10.89.127.241/26 brd 10.89.127.255 scope global cscotun0
       valid_lft forever preferred_lft forever

CISCO VPN Interface connection got lease 10.89.127.241 And this is the interface I need cloud-init to host and push as target for vm during build

Image pull works… vault gets all its correct keys / values / secrets. Image is pulled and cached local, and pushed to vCenter / cluster. VM creates and boots… but as example noted below, it defines cloud-init target for pull to pull against remote system’s first interface, not the VPN interface on that network.

GNU GRUB version 2.04
Minimal BASH-like line editing is supported... blah blah
grub> linux /casper/vmlinux --- autoinstall ds="nocloud-net;seedfrom=http://172.16.100.146:8027....blah


My idea is to set packer variable via prompt (doing that aready for other values) and somehow get packer to use this “IP” for listener of cloud-init services and pass that to build

Any articles / ideas on how to do this?

Thanks

I will post here to answer my own question as a co-worker helped me figure this out.

variable for this IP to be set is already in place in : common.pkrvars.hcl

// Boot and Provisioning Settings
common_data_source = “http”

common_http_ip = null # Remarked out so it does not override input from shell variables

common_http_port_min = 8000
common_http_port_max = 8099
common_ip_wait_timeout = “20m”
common_shutdown_timeout = “15m”

you have to set in shell the variable

Ex:

Need correct packer variable for interface

echo "Please input IP for Interface that packer will use to connect to deployment target:Ex: VPN to site 172.16.100.144 "
echo “Here are your IPs”
ip ad |grep inet|awk ‘{print $2}’
read VAR_common_http_ip
export PKR_VAR_common_http_ip=$VAR_common_http_ip
echo
echo Site connection IP is set to $PKR_VAR_common_http_ip

With special PKR_VAR_ prefix that will mean packer will pull into shell when it runs.

Then remarking out "# common_http_ip = null " so that it does not override your shell variable with value of “null”

Once we figured out that… it worked.