21 views
Skip to first unread message

Gopal Dhapa

unread,
May 5, 2019, 9:31:37 AM5/5/19
to ansible...@googlegroups.com
Hello Team,

How to see centos server host name using ansible.

Please suggest

Thanks in advance.

Thank you
Gopal Dhapa

Gopal Dhapa

unread,
May 5, 2019, 9:33:14 AM5/5/19
to ansible...@googlegroups.com
How to set host name of centos using ansible.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFuBnhjRySTvj6x8T6kDz7WcWAQrcE1mh-djYt5%3DAAjhH2BapA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Lozada De La Matta

unread,
May 5, 2019, 10:30:47 AM5/5/19
to ansible...@googlegroups.com


For more options, visit https://groups.google.com/d/optout.


--

Jonathan Cha'gara Lozada De La Matta

He / Him / His

Automation Practice

Senior Automation Consultant & Automation CoP Manager

Red Hat


 

d...@linder.org

unread,
May 5, 2019, 3:44:21 PM5/5/19
to Ansible Project
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.

Gopal Dhapa

unread,
May 7, 2019, 10:32:07 PM5/7/19
to ansible...@googlegroups.com
Thank you it's working now.

Thank you
Gopal Dhapa

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages