# Pass VM name to ansible

**URL:** <https://forum.ansible.com/t/pass-vm-name-to-ansible/34179>\
**Category:** Ansible Project\
**Created:** [November 11, 2020, 1:04pm UTC](https://forum.ansible.com/t/pass-vm-name-to-ansible/34179 "2020-11-11T13:04:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eoghan\_O\_Hara](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@Eoghan\_O\_Hara](https://forum.ansible.com/u/Eoghan_O_Hara)\
**Post date:** [November 11, 2020, 1:04pm UTC](https://forum.ansible.com/t/pass-vm-name-to-ansible/34179/1 "2020-11-11T13:04:55Z")

</div>

Hi all,

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.

See my packer JSON:

{  
“builders”: [  
{  
“boot\_command”: [  
“ text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg”  
],  
“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”,  
“[http://mirrors.mit.edu/centos/7/isos/x86\_64/CentOS-7-x86\_64-Minimal-2003.iso](http://mirrors.mit.edu/centos/7/isos/x86_64/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”: “”  
}  
}

Thanks,  
Eoghan

---

<div class="post-metadata">

**Author:** ![Eoghan\_O\_Hara](https://avatars.discourse-cdn.com/v4/letter/e/9f8e36/32.png) [@Eoghan\_O\_Hara](https://forum.ansible.com/u/Eoghan_O_Hara)\
**Post date:** [November 11, 2020, 1:19pm UTC](https://forum.ansible.com/t/pass-vm-name-to-ansible/34179/2 "2020-11-11T13:19:50Z")

</div>

Would expect that I will use this, just not sure how or what I can pass in: [https://www.packer.io/docs/provisioners/ansible#extra\_arguments](https://www.packer.io/docs/provisioners/ansible#extra_arguments)
