# Setting hostname

**URL:** <https://forum.ansible.com/t/setting-hostname/19254>\
**Category:** Ansible Project\
**Created:** [September 14, 2015, 9:15am UTC](https://forum.ansible.com/t/setting-hostname/19254 "2015-09-14T09:15:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kuberboef](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kuberboef](https://forum.ansible.com/u/Kuberboef)\
**Post date:** [September 14, 2015, 9:15am UTC](https://forum.ansible.com/t/setting-hostname/19254/1 "2015-09-14T09:15:03Z")

</div>

Morning all

I am sure this has been asked before, I just struggle to find it.  
I cloned [https://github.com/knopki/ansible-hostname](https://github.com/knopki/ansible-hostname)  
Looks good and vagrant calls ansible successfully and all goes wel, untill…  
I need to specify variables in the vars/main.yml file.

hostname\_name = mozzi  
hostname\_domain = [mozzi.mydomain.com](http://mozzi.mydomain.com)

My error:  
ERROR: vars from ‘/home/stefaansm/trusty64/Ansible/ansible-hostname/vars/main.yml’ are not a dict

Now being a nube at this and not a programmers backside, I seem to be lost here and doc’s seem scarce.

Mozzi

---

<div class="post-metadata">

**Author:** ![Frank\_Perks](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@Frank\_Perks](https://forum.ansible.com/u/Frank_Perks)\
**Post date:** [September 14, 2015, 4:01pm UTC](https://forum.ansible.com/t/setting-hostname/19254/2 "2015-09-14T16:01:34Z")

</div>

ansible-hostname is a role, and should be in the roles directory.

Assuming /home/stefaansm/trusty64/Ansible/ is where your playbooks are. Then ansible-hostname should be located at /home/stefaansm/trusty64/Ansible/roles/ansible-hostname

---

<div class="post-metadata">

**Author:** ![Kuberboef](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kuberboef](https://forum.ansible.com/u/Kuberboef)\
**Post date:** [September 15, 2015, 5:41am UTC](https://forum.ansible.com/t/setting-hostname/19254/3 "2015-09-15T05:41:52Z")

</div>

Morning

Okay contents of ~/trusty64/Ansible  
Ansible  
│ ├── ansible-hostname  
│ │ ├── defaults  
│ │ │ └── main.yml  
│ │ ├── LICENSE  
│ │ ├── meta  
│ │ │ └── main.yml  
│ │ ├── README.md  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ └── vars  
│ │ └── main.yml

│ └── playbook.yml

config in playbook:

- hosts: all  
roles:
- { role: ansible-hostname }

So according to me the role is found and executed correctly, but there is something wrong  
with the way I specify the hostnames in vars/main.yml.

From the README.md:

Role Variables

---

<div class="post-metadata">

**Author:** ![Frank\_Perks](https://avatars.discourse-cdn.com/v4/letter/f/90ced4/32.png) [@Frank\_Perks](https://forum.ansible.com/u/Frank_Perks)\
**Post date:** [September 15, 2015, 12:58pm UTC](https://forum.ansible.com/t/setting-hostname/19254/4 "2015-09-15T12:58:38Z")

</div>

Like i said move your ansible-hostname into the roles folder (if you don’t have one make one). As far as i know ansible only loads roles from the roles folder, which is probably your issue.

Also his documentation is wrong, he doesn’t use hostname\_domain, he actually in the code uses hostname\_fqdn instead.

---

<div class="post-metadata">

**Author:** ![Paul\_Markham](https://avatars.discourse-cdn.com/v4/letter/p/9d8465/32.png) [@Paul\_Markham](https://forum.ansible.com/u/Paul_Markham)\
**Post date:** [September 21, 2015, 5:49am UTC](https://forum.ansible.com/t/setting-hostname/19254/5 "2015-09-21T05:49:25Z")

</div>

YAML doesn’t use an equals sign, instead use a colon:

---

<div class="post-metadata">

**Author:** ![Kuberboef](https://avatars.discourse-cdn.com/v4/letter/k/7feea3/32.png) [@Kuberboef](https://forum.ansible.com/u/Kuberboef)\
**Post date:** [September 21, 2015, 6:19am UTC](https://forum.ansible.com/t/setting-hostname/19254/6 "2015-09-21T06:19:19Z")

</div>

Thanx mate, figured that one out the hard way! 😃
