Passing ESXi remote_password from a variable

174 views
Skip to first unread message

j...@sanger.ac.uk

unread,
Mar 9, 2016, 3:42:52 AM3/9/16
to Packer
I have a builder running on a vmware ESXi remote server:-


  "builders": [
      {
      "type": "vmware-iso",
      "vmx_template_path": "packer.vmx",
      "guest_os_type": "ubuntu-64",
      "remote_type": "esx5",
      "remote_username": "vmbuildadmin",
      "remote_host": "{{ user `vmware_host` }}",
      "remote_private_key_file": "{{ user `vm_private_key` }}",
      "remote_datastore": "{{ user `vm_datastore` }}",
      "remote_password": "{{ user `vm_pass` }}",
      "iso_url": "{{ user `iso_url` }}",
      "iso_checksum": "{{ user `iso_checksum` }}",
      "iso_checksum_type": "md5",
      "vnc_port_min": 5970,
      "vnc_port_max": 5990,
      "ssh_username": "{{user `packer_username`}}",
      "ssh_password": "{{user `packer_password`}}",
      "ssh_timeout": "60m",
      "shutdown_command": "echo '{{user `packer_username`}}' | sudo -S shutdown -P now",
      "http_directory": "data/",
      "headless": false,
      "version": 8,
      "tools_upload_flavor": "linux",
      "format": "ovf",
      "boot_command": [
        "<esc><esc><enter><wait>",
        "/install/vmlinuz  ",
        " auto",
        " console-setup/ask_detect=false",
        " console-setup/layoutcode=us",
        " console-setup/modelcode=pc105",
        " debconf/frontend=noninteractive",
        " debian-installer=en_US",
        " fb=false",
        " preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/preseed.cfg",
        " initrd=/install/initrd.gz",
        " kbd-chooser/method=us",
        " keyboard-configuration/layout=USA",
        " keyboard-configuration/variant=USA",
        " hostname={{ .Name }} ",
        " locale=en_US",
        " netcfg/get_domain=vm",
        " netcfg/get_hostname={{ .Name }}",
        " noapic",
        " -- ",
        "<enter><wait>"
        ]
      },

This builds images fine, the bit that fails is the ovftool conversion of ovf at the end of the build. This seems to be because the remote_password field is not getting filled in correctly to the command that's being called at export time.

I want to source the variable vm_pass from the command line so it can be prompted for in a wrapper script with the option :   -var 'vm_pass=${vm_password}'

If I do this it simply gets filled with a blank, however if I specify a vm_pass variable in the variables section of the template it works.

I feel I must be missing something obvious, any suggestions?

Thanks,

Jon

Alvaro Miranda Aguilera

unread,
Mar 9, 2016, 7:48:20 PM3/9/16
to packe...@googlegroups.com
Hello,

If you are using bash, don't use single quotes.

So basically use:

   -var "vm_pass=${vm_password}"


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/ed061b51-b008-4240-9a7f-d09ed7966dca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

j...@sanger.ac.uk

unread,
Mar 10, 2016, 3:53:08 AM3/10/16
to Packer


On Thursday, March 10, 2016 at 12:48:20 AM UTC, Alvaro Miranda Aguilera wrote:
Hello,

If you are using bash, don't use single quotes.

So basically use:

   -var "vm_pass=${vm_password}"

Unfortunately it's not as simple as that (it never is!) the bash wrapper does a bit more, here's the full excerpt


if [ ${vmware} -eq 1 ] ; then
   
if [ "x${VMWARE_PASSWORD}" == "x" ]; then
        echo
"Password require to connect to the machine ${VMWARE_BUILD_HOST}"

        read
-s  -p Password: VMWARE_PASSWORD
   
fi    
    echo
""
    variables
+="-var 'vm_pass=${VMWARE_PASSWORD}' "
fi

echo
"Logging to ${PACKER_LOG_PATH}"

BUILD
=$( join , ${builders} )

if [ $ACTION == 'validate' ] ; then
#    echo $VMWARE_PASSWORD
    echo $PACKER_BIN $ACTION
-only=$BUILD $variables template.json
fi

$PACKER_BIN $ACTION
-only=$BUILD $variables template.json


Running with the "validate" option the script outputs the command line it will pass to packer:-

./packer.sh validate vmware
** VALIDATING TEMPLATE ONLY
VMware
Password require to connect to the machine wtgc-vmbd-01.internal.sanger.ac.uk
Password:
Logging to /tmp/packer_log.28744

/home/jjn/bin/packer validate -only=vmware-iso -var 'vm_pass=password' template.json
Template validated successfully.




 

j...@sanger.ac.uk

unread,
Mar 10, 2016, 4:45:47 AM3/10/16
to Packer
I've solved this!

It was the shell quoting in the end.

if you quote the whole argument to packer e.g. -var 'var=value' then the variable doesn't appear to get set. The solution here was to do -var var='value'.

This appears to do the right thing, using the syntax from "setting variables" section of the user variables document:-

$ packer build \
   
-var 'aws_access_key=foo' \
   
-var 'aws_secret_key=bar' \
   
template.json

Works fine on the command line, but doesn't from within the wrapper script!
Reply all
Reply to author
Forward
0 new messages