Cloud-init, Ansible and VM/Hostname

With Cloud-Init, Am I able to pass the {name} variable of the VM name to Ansible? I want to use Ansible to make the /etc/hosts file. I have it set as a boot cmd in Cloud-Init now. Any ideas?