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_hostname_f: a platform fact mimicking `hostname -f` #56424

Open
wants to merge 1 commit into
base: devel
from

Conversation

Projects
None yet
3 participants
@dexpl
Copy link

commented May 15, 2019

SUMMARY

There are some issues with ansible_fqdn platform fact (#38777, #9972, maybe others). I recently stuck into another one: if you have multiple PTR records with different names for one IP address, ansible_fqdn value is randomly set to one of those names. For example, Mikrotik built-in DNS server lets you have multiple names resolving to the same IP, but it gives you no option to choose which name to resolve that IP into via PTR record — it just creates as many PTRs for that IP as many names you give it. Nevertheless, hostname -f always returns the same, there was a hint about it.

Due to this, I propose a new fact, ansible_hostname_f, which value is populated the same way hostname -f works:
Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is the part after the first dot.
(from man hostname). I also propose ansible_hostname_d mimicking hostname -d.

In order not to break the backwards compatibility with existing setups, I don't replace any existing facts but add new ones instead.

In order to maintain cross-platform portability this implementation does not call hostname(1) binary but implements the same algo on python using the already-utilised socket module.

Please consider applying.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

lib/ansible/module_utils/facts/system/platform.py

ADDITIONAL INFORMATION

@dexpl

This comment has been minimized.

Copy link
Author

commented May 15, 2019

bot_status

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

Components

lib/ansible/module_utils/facts/system/platform.py
support: core
maintainers:

Metadata

waiting_on: dexpl
changes_requested_by: null
needs_info: False
needs_revision: True
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: unstable
shippable_status: failure
maintainer_shipits (module maintainers): False
community_shipits (namespace maintainers): False
ansible_shipits (core team members): False
shipit_actors (maintainer or core team member): None
shipit_actors_other:
automerge: automerge shipit test failed

click here for bot help

@dexpl

This comment has been minimized.

Copy link
Author

commented May 15, 2019

ready_for_review

As far as I can see, failed tests are due to some issues with shippable itself and not related to this PR. Please correct me if I'm wrong and give a hint about my further actions.

@dexpl dexpl closed this May 16, 2019

@dexpl dexpl reopened this May 16, 2019

@dexpl dexpl closed this May 16, 2019

@dexpl dexpl reopened this May 16, 2019

@@ -53,6 +53,11 @@ def collect(self, module=None, collected_facts=None):

platform_facts['domain'] = '.'.join(platform_facts['fqdn'].split('.')[1:])

# this is what `hostname -f` returns
platform_facts['hostname_f'] = socket.getaddrinfo(socket.gethostname(), None, 0, socket.SOCK_DGRAM, 0, socket.AI_CANONNAME)[0][3]

This comment has been minimized.

Copy link
@bcoca

bcoca May 16, 2019

Member

not really, using your code i get: ansible_hostname_f": "localhost",
but hostname -f gives me erebos.

This comment has been minimized.

Copy link
@dexpl

dexpl May 19, 2019

Author

That's surprising. Could you describe your environment?

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 16, 2019

@dexpl this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

@dexpl dexpl closed this May 16, 2019

@dexpl dexpl reopened this May 16, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented May 16, 2019

@dexpl this PR contains the following merge commits:

Please rebase your branch to remove these commits.

click here for bot help

lib/ansible/module_utils/facts/system/platform.py: added `ansible_hos…
…tname_f`, which value is always the same as the one of `hostname -f`

@dexpl dexpl force-pushed the dexpl:hostname_f branch from 64da47c to ea4456f May 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.