# This topic needs a title

**URL:** <https://forum.ansible.com/t/this-topic-needs-a-title/30267>\
**Category:** Ansible Project\
**Created:** [May 5, 2019, 1:31pm UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267 "2019-05-05T13:31:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopal\_Dhapa](https://avatars.discourse-cdn.com/v4/letter/g/dec6dc/32.png) [@Gopal\_Dhapa](https://forum.ansible.com/u/Gopal_Dhapa)\
**Post date:** [May 5, 2019, 1:31pm UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267/1 "2019-05-05T13:31:16Z")

</div>

Hello Team,

How to see centos server host name using ansible.

Please suggest

Thanks in advance.

Thank you  
Gopal Dhapa

---

<div class="post-metadata">

**Author:** ![Gopal\_Dhapa](https://avatars.discourse-cdn.com/v4/letter/g/dec6dc/32.png) [@Gopal\_Dhapa](https://forum.ansible.com/u/Gopal_Dhapa)\
**Post date:** [May 5, 2019, 1:32pm UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267/2 "2019-05-05T13:32:55Z")

</div>

How to set host name of centos using ansible.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [May 5, 2019, 2:30pm UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267/3 "2019-05-05T14:30:18Z")

</div>

[https://docs.ansible.com/ansible/latest/modules/hostname\_module.html](https://docs.ansible.com/ansible/latest/modules/hostname_module.html)

---

<div class="post-metadata">

**Author:** ![dan\_linder](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dan_linder/32/3833_2.png) [@dan\_linder](https://forum.ansible.com/u/dan_linder)\
**Post date:** [May 5, 2019, 7:44pm UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267/4 "2019-05-05T19:44:20Z")

</div>

To see the hostname or use it in your playbook, you use the ansible\_hostname or ansible\_fqdn variables.

As Jonathan Cha’gara Lozada De La Matta mentioned, the hostname module can set it, but many applications still (incorrectly) rely on it also being in the /etc/hosts file. Here’s what I’ve done in my playbooks:

`

- name: Setup hostname on system as {{ network\_hostname }}.{{ network\_dnsdomain }}  
hostname:  
name: “{{ network\_hostname }}.{{ network\_dnsdomain }}”

- name: Add hostname to local /etc/hosts file  
lineinfile:  
dest: /etc/hosts  
state: present  
regexp: “^{{ network\_ipaddr }}”  
line: “{{ network\_ipaddr }} {{ network\_hostname }}.{{ network\_dnsdomain }} {{ network\_hostname }}”  
`

In this case, I set network\_\* variables before calling this - my systems occasionally confuse Ansible and the ansible\_hostname/ansible\_fqdn are incorrect.

---

<div class="post-metadata">

**Author:** ![Gopal\_Dhapa](https://avatars.discourse-cdn.com/v4/letter/g/dec6dc/32.png) [@Gopal\_Dhapa](https://forum.ansible.com/u/Gopal_Dhapa)\
**Post date:** [May 8, 2019, 2:31am UTC](https://forum.ansible.com/t/this-topic-needs-a-title/30267/5 "2019-05-08T02:31:20Z")

</div>

Thank you it’s working now.

Thank you  
Gopal Dhapa
