I am using Packer with Ansible. What is the best way to pass in the VM name (generated in Packer) to Ansible? I need it for naming directories in a task.
{
"builders": [
{
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 50000,
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"guest_os_type": "RedHat_64",
"headless": true,
"http_directory": "http",
"iso_checksum": "sha256:659691c28a0e672558b003d223f83938f254b39875ee7559d1a4a14c79173193",
"iso_urls": [
"CentOS-7-x86_64-Minimal-2003.iso",
],
"shutdown_command": "echo 'vagrant'|sudo -S /sbin/halt -h -p",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_timeout": "1800s",
"ssh_username": "vagrant",
"type": "virtualbox-iso",
"name": "infoblox-{{isotime \"20060102-150405\"}}",
"vm_name": "infoblox-{{isotime \"20060102-150405\"}}",
"output_directory": "{{user `output_dir`}}/infoblox-{{isotime \"20060102-150405\"}}",
"vboxmanage": [
[
"modifyvm",
"{{.Name}}",
"--memory",
"8000"
],
[
"modifyvm",
"{{.Name}}",
"--cpus",
"3"
],
[
"sharedfolder",
"add",
"{{.Name}}",
"--name",
"mountdir",
"--hostpath",
"{{user `mount_dir`}}",
"--automount"
]
],
"vboxmanage_post": [
[
"sharedfolder",
"remove",
"{{.Name}}",
"--name",
"mountdir"
]
],
"virtualbox_version_file": ".vbox_version"
}
],
"provisioners": [
{
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/ansible.sh",
"type": "shell"
},
{
"galaxy_file": "../shared/requirements.yml",
"playbook_file": "../shared/main.yml",
"role_paths": [
"../shared/roles/common"
],
"type": "ansible-local"
},
{
"execute_command": "echo 'vagrant' | {{.Vars}} sudo -S -E bash '{{.Path}}'",
"script": "scripts/cleanup.sh",
"type": "shell"
}
],
"variables": {
"mount_dir": "",
"output_dir": ""
}
}