Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible_fqdn different from ansible_hostname #38777

Closed
zakabluk opened this issue Apr 14, 2018 · 3 comments
Closed

ansible_fqdn different from ansible_hostname #38777

zakabluk opened this issue Apr 14, 2018 · 3 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@zakabluk
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Generated facts with mistake.

ANSIBLE VERSION

ansible 2.4.2.0
python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

CONFIGURATION

default config

OS / ENVIRONMENT

CentOS Linux release 7.4.1708 (Core)

SUMMARY

I generated facts for server and have had result
Connecting to ecsc00a01c56.example.com [10.6.195.4] port 22.\

    "ansible_fqdn": "ecsc00100ea6.example.com",  - wrong name!
    "ansible_hostname": "ecsc00a01c56", 
     ansible_nodename": "ecsc00a01c56
      "ohai_fqdn": "ecsc00a01c56.example.com", 
    "ohai_hostname": "ecsc00a01c56", 

bash# hostname
ecsc00a01c56.example.com
server use CentOS Linux release 7.4.1708 (Core)


@ansibot
Copy link
Contributor

ansibot commented Apr 14, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 14, 2018
@sivel
Copy link
Member

sivel commented Apr 16, 2018

Ansible populates the value of ansible_fqdn using the socket.getfqdn() function.

getfqdn is documented as:

Get fully qualified domain name from name.

An empty argument is interpreted as meaning the local host.

First the hostname returned by gethostbyaddr() is checked, then
possibly existing aliases. In case no FQDN is available, hostname
from gethostname() is returned.

So the process that is followed is to use socket.gethostname which should return the locally configured hostname, then use that value to perform a DNS lookup of that configured hostname, and if any aliases are found, potentially from /etc/hosts that are aliases including an FQDN, that alias will be returned.

Here is an example:

>>> import socket
>>> socket.gethostname()
'vivo'
>>> socket.gethostbyaddr('vivo')
('vivo', ['foo.bar.baz'], ['127.0.1.1'])
>>> socket.getfqdn()
'foo.bar.baz'

Based on what we deem ansible_fqdn to be, this value is correct, but has the ability to be tainted by DNS or /etc/hosts records

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Apr 16, 2018
@sivel sivel removed the needs_triage Needs a first human triage before being processed. label Apr 16, 2018
@zakabluk
Copy link
Author

Hi! The problem was in wrong PTR record.

@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

No branches or pull requests

3 participants