using variables

100 views
Skip to first unread message

Andrew Meyer

unread,
Jan 24, 2019, 11:39:22 PM1/24/19
to Packer
So after the previous post I am trying to make my json file dynamic by making anything I can into a variable.  However now I am getting the following error:

 output will be in this color.

Warnings for build '':

* Headless mode uses VNC to retrieve output. Since VNC has been disabled,
you won't be able to see any output.

Build '' errored: Failed creating VMware driver: Unable to initialize any driver for this platform. The errors
from each driver are shown below. Please fix at least one driver
to continue:
* exec: "vmware": executable file not found in $PATH
* exec: "vmware": executable file not found in $PATH
* exec: "vmplayer": executable file not found in $PATH
* exec: "vmplayer": executable file not found in $PATH


==> Some builds didn't complete successfully and had errors:
--> : Failed creating VMware driver: Unable to initialize any driver for this platform. The errors
from each driver are shown below. Please fix at least one driver
to continue:
* exec: "vmware": executable file not found in $PATH
* exec: "vmware": executable file not found in $PATH
* exec: "vmplayer": executable file not found in $PATH
* exec: "vmplayer": executable file not found in $PATH


==> Builds finished but no artifacts were created.

Here is what the config looks like now:
  "builders": [
    { 
      "name": "{{user `name`}}",
      "tools_upload_flavor": "{{user `tools_upload_flavor`}}",
      "headless": "true",
      "ovftool_options": [ "--allowExtraConfig", "--noSSLVerify=true", "true" ],
      "cpus": "1",
      "disk_size": "61440",
      "disk_type_id": "{{user `disk_type_id`}}",
      "guest_os_type": "{{user `guest_os_type`}}",
      "iso_checksum": "38d5d51d9d100fd73df031ffd6bd8b1297ce24660dc8c13a3b8b4534a4bd291c",
      "iso_checksum_type": "sha256",
      "keep_registered": true,
      "memory": "2048",
      "network_adapter_type": "{{user `network_adapter_type`}}",
      "disable_vnc": "true",
      "remote_datastore": "{{user `remote_datastore`}}",
      "remote_host": "{{user `remote_host`}}",
      "remote_username": "{{user `remote_username`}}",
      "remote_password": "{{user `remote_password`}}",
      "remote_type": "{{user `remote_type`}}",
      "skip_compaction": true,
      "usb": "true",
      "ssh_password": "{{user `ssh_password`}}",
      "ssh_username": "root",
      "ssh_wait_timeout": "60m",
      "boot_wait": "7s",
      "type": "vmware-iso",
      "vm_name": "{{user `vm_name`}}",
      "shutdown_command": "echo 'shutdown -P now'"
    }
  ]
}


I tried running the packer json file with the following syntax:
[andrew.meyer@automation01 vmware]$ packer build -var-file=variables.json centos-esxi.json 
Usage: packer build [options] TEMPLATE

  Will execute multiple builds in parallel as defined in the template.
  The various artifacts created by the template will be outputted.

Options:

  -color=false                  Disable color output. (Default: color)
  -debug                        Debug mode enabled for builds.
  -except=foo,bar,baz           Build all builds other than these.
  -only=foo,bar,baz             Build only the specified builds.
  -force                        Force a build to continue if artifacts exist, deletes existing artifacts.
  -machine-readable             Produce machine-readable output.
  -on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
  -parallel=false               Disable parallelization. (Default: parallel)
  -timestamp-ui                 Enable prefixing of each ui output with an RFC3339 timestamp.
  -var 'key=value'              Variable for templates, can be used multiple times.
  -var-file=path                JSON file containing user variables.
invalid value "variables.json" for flag -var-file: Error reading variables in 'variables.json': invalid character '"' after object key:value pair
[andrew.meyer@automation01 vmware]$ 


The logs show that it has discovered the vmware plugin.  I suspect I changed more than I should have or I have a typo....

Rickard von Essen

unread,
Jan 25, 2019, 3:10:14 AM1/25/19
to packe...@googlegroups.com
Could you post your variables.json

--
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/3ddef954-230d-4e36-a3db-36238350a056%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Meyer

unread,
Jan 25, 2019, 12:15:39 PM1/25/19
to Packer
Here you go

{
 
"esxi_host": "10.150.1.35",
 
"esxi_datastore": "datastore-nas",
 
"esxi_username": "root",
 
"esxi_password": "password"
 
"esxi_network": "v10101-prod",
 
"remote_type": "esx5",
 
"remote_host": "10.150.1.35",
 
"remote_datastore": "datastore-nas
  "
remote_username": "root",
  "
remote_password": "password",
  "
version": "13",
  "
name": "test123",
  "
tools_upload_flavor": "{{user `tools_upload_flavor`}}",
  "
cpus": "1",
  "
disk_size": "61440",
  "
disk_type_id": "thin",
  "
guest_os_type": "centos7-64",
  "
iso_checksum": "38d5d51d9d100fd73df031ffd6bd8b1297ce24660dc8c13a3b8b4534a4bd291c",
  "
iso_checksum_type": "sha256",
  "
iso_url": "http://10.150.1.9/isos/CentOS-7-x86_64-Minimal-1810.iso",

 
"keep_registered": true,
 
"memory": "2048",

 
"network_adapter_type": "vmxnet3",
 
"disable_vnc": "true",
 
"remote_datastore": "datastore-nas",

 
"skip_compaction": true,
 
"usb": "true",

 
"ssh_password": "password",

 
"ssh_username": "root",
 
"ssh_wait_timeout": "60m",
 
"boot_wait": "7s",
 
"type": "vmware-iso",

 
"vm_name": "test123",

Rickard von Essen

unread,
Jan 25, 2019, 12:27:16 PM1/25/19
to packe...@googlegroups.com
After datastore-nas there is missing a "

Andrew Meyer

unread,
Jan 28, 2019, 9:56:21 PM1/28/19
to Packer
Ok I fixed that.  I am still getting the same errors.  I have also read that I needed to install vmware-vix.  Tried that.  Same thing.

Any thoughts?

Rickard von Essen

unread,
Jan 29, 2019, 4:56:00 AM1/29/19
to packe...@googlegroups.com
Just open your json file in an editor which checks your syntax. 

Andrew Meyer

unread,
Jan 29, 2019, 9:15:18 AM1/29/19
to Packer
I found the issue.  For some reason packer doesn't like me using a variable for the remote_type.  Fixed that but now getting this:

packer build centos-esxi.json
 output will be
in this color.

2 error(s) occurred:

* remote_host must be specified
* exporting the vm (with ovftool) requires that you set a value for remote_password

So I tried running it with this syntax:
$ packer build -var-file=variables.json centos-esxi.json
And got this:

Usage: packer build [options] TEMPLATE

  Will execute multiple builds in parallel as defined in the template.
  The various artifacts created by the template will be outputted.

Options:

  -color=false                  Disable color output. (Default: color)
  -debug                        Debug mode enabled for builds.
  -except=foo,bar,baz           Build all builds other than these.
  -only=foo,bar,baz             Build only the specified builds.
  -force                        Force a build to continue if artifacts exist, deletes existing artifacts.
  -machine-readable             Produce machine-readable output.
  -on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
  -parallel=false               Disable parallelization. (Default: parallel)
  -timestamp-ui                 Enable prefixing of each ui output with an RFC3339 timestamp.
  -var 'key=value'              Variable for templates, can be used multiple times.
  -var-file=path                JSON file containing user variables.
invalid value "variables.json" for flag -var-file: Error reading variables in 'variables.json': json: cannot unmarshal bool into Go value of type string


Rickard von Essen

unread,
Jan 29, 2019, 9:18:28 AM1/29/19
to packe...@googlegroups.com
true should be quoted, all variables are string pairs. 

Andrew Meyer

unread,
Jan 29, 2019, 9:37:20 AM1/29/19
to Packer
Like this?

[andrew.meyer@automation01 vmware]$ packer build -var-file="variables.json" centos-esxi.json 
Usage: packer build [options] TEMPLATE

  Will execute multiple builds in parallel as defined in the template.
  The various artifacts created by the template will be outputted.

Options:

  -color=false                  Disable color output. (Default: color)
  -debug                        Debug mode enabled for builds.
  -except=foo,bar,baz           Build all builds other than these.
  -only=foo,bar,baz             Build only the specified builds.
  -force                        Force a build to continue if artifacts exist, deletes existing artifacts.
  -machine-readable             Produce machine-readable output.
  -on-error=[cleanup|abort|ask] If the build fails do: clean up (default), abort, or ask.
  -parallel=false               Disable parallelization. (Default: parallel)
  -timestamp-ui                 Enable prefixing of each ui output with an RFC3339 timestamp.
  -var 'key=value'              Variable for templates, can be used multiple times.
  -var-file=path                JSON file containing user variables.
invalid value "variables.json" for flag -var-file: Error reading variables in 'variables.json': json: cannot unmarshal bool into Go value of type string
[andrew.meyer@automation01 vmware]$ 

Rickard von Essen

unread,
Jan 29, 2019, 10:55:12 AM1/29/19
to packe...@googlegroups.com
These should be quoted like this:

"skip_compaction": "true",
"keep_registered": "true",

Andrew Meyer

unread,
Jan 29, 2019, 12:48:45 PM1/29/19
to Packer
Fixed that, same thing.

:-(

Rickard von Essen

unread,
Jan 29, 2019, 12:59:57 PM1/29/19
to packe...@googlegroups.com
Could you submit your latest version of temple and vars file and the error message you are getting. 

Andrew Meyer

unread,
Jan 29, 2019, 1:36:38 PM1/29/19
to Packer
vars.json

cat ~/Ops/packer/vmware/vars.json
{
 
"esxi_host": "10.150.1.35",
 
"esxi_datastore": "datastore-nas",
 
"esxi_username": "root",

 
"esxi_password": "infotech",

 
"esxi_network": "v10101-prod",
 
"remote_type": "esx5",
 
"remote_host": "10.150.1.35",

 
"remote_datastore": "datastore-nas",
 
"remote_username": "root",
 
"remote_password": "removed",

 
"version": "13",
 
"name": "test123",

 
"tools_upload_flavor": "linux",

 
"cpus": "1",
 
"disk_size": "61440",
 
"disk_type_id": "thin",
 
"guest_os_type": "centos7-64",
 
"iso_checksum": "38d5d51d9d100fd73df031ffd6bd8b1297ce24660dc8c13a3b8b4534a4bd291c",
 
"iso_checksum_type": "sha256",

 
"iso_url": "http://10.150.1.7/isos/CentOS-7-x86_64-Minimal-1810.iso",
 
"vnc_disable_password": "true",
 
"keep_registered": "true",

 
"memory": "2048",
 
"network_adapter_type": "vmxnet3",

 
"skip_compaction": "true",
 
"disable_vnc": "false",
 
"usb": "true",
 
"ssh_password": "removed",

 
"ssh_username": "root",
 
"ssh_wait_timeout": "60m",
 
"boot_wait": "7s",
 
"type": "vmware-iso",
 
"vm_name": "test123",

 
"shutdown_command": "echo 'shutdown -P now'",
 
"boot_command": [ "<tab> text ks=http://10.150.1.7/centos7/ks.cfg<enter><wait>" ]
}


centos-esxi.json
cat ~/Ops/packer/vmware/centos-esxi.json
{
 
"builders": [

   
{
     
"name": "{{user `name`}}",
     
"tools_upload_flavor": "{{user `tools_upload_flavor`}}",
     
"headless": "true",
     
"ovftool_options": [ "--allowExtraConfig", "--noSSLVerify=true", "true" ],
     
"cpus": "1",
     
"disk_size": "61440",
     
"disk_type_id": "{{user `disk_type_id`}}",
     
"guest_os_type": "{{user `guest_os_type`}}",
     
"iso_checksum": "38d5d51d9d100fd73df031ffd6bd8b1297ce24660dc8c13a3b8b4534a4bd291c",
     
"iso_checksum_type": "sha256",

     
"iso_url": "http://10.150.1.7/isos/CentOS-7-x86_64-Minimal-1810.iso",
     
"keep_registered": "true",

     
"memory": "2048",
     
"network_adapter_type": "{{user `network_adapter_type`}}",

     
"disable_vnc": "{{user `disable_vnc`}}",
     
"vnc_disable_password": "{{user `vnc_disable_password`}}",

     
"remote_datastore": "{{user `remote_datastore`}}",
     
"remote_host": "{{user `remote_host`}}",
     
"remote_username": "{{user `remote_username`}}",
     
"remote_password": "{{user `remote_password`}}",

     
"remote_type": "esx5",
     
"skip_compaction": "true",

     
"usb": "true",
     
"ssh_password": "{{user `ssh_password`}}",
     
"ssh_username": "root",
     
"ssh_wait_timeout": "60m",
     
"boot_wait": "7s",
     
"type": "vmware-iso",
     
"vm_name": "{{user `vm_name`}}",

     
"shutdown_command": "echo 'shutdown -P now'",
     
"boot_command": [ "<tab> text ks=http://10.150.1.7/centos7/ks.cfg<enter><wait>" ]
   
}
 
]
}


Rickard von Essen

unread,
Jan 29, 2019, 4:39:53 PM1/29/19
to packe...@googlegroups.com
The boot_command in the variables file is an array, just remove it since you don't use it. I would advise you to not add any variables that you don't really need. Instead add the when you really have the need too use it. 

Andrew Meyer

unread,
Jan 30, 2019, 12:35:02 PM1/30/19
to Packer
Got it working! TY!  Had some trailing ',' commas to fix.  However I want to use the kickstart file to automate the build.   What would be the best way to do this?

Rickard von Essen

unread,
Jan 30, 2019, 12:51:42 PM1/30/19
to packe...@googlegroups.com
I want to use the kickstart file to automate the build.   What would be the best way to do this?

Could you explain more? What do you want help with?

There are some good reference Packer template here: 

Andrew Meyer

unread,
Jan 30, 2019, 12:53:24 PM1/30/19
to packe...@googlegroups.com
Let me check that out first.  I'll probably start a new thread after I research this.

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/6PCjTpzHKNQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt_7eQ_cSPondKBni5jDOkYm9-ENQwP5M9TOZMpbpX8R8w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages