question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

server.hostname fails without hostname command

See original GitHub issue

Describe the bug

[testhost] sh: hostname: command not found
[testhost] Error: could not load fact: hostname

The hostname fact fails on machines without the hostname command, which should be somewhat common nowadays.

To Reproduce Run pyinfra testhost.localdomain all-facts against a host that does not have the hostname command installed.

Expected behavior The hostname should be found without using hostname. Other ways to find this out would be via hostnamectl, which is included on every system running systemd, more specifically hostnamectl status --static or hostnamectl status --transient, or /etc/hostname or /proc/sys/kernel/hostname.

Meta

  • Include output of pyinfra --support.
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Linux
      Platform: Linux-5.9.1-arch1-1-x86_64-with-glibc2.2.5
      Release: 5.9.1-arch1-1
      Machine: x86_64
    pyinfra: v1.2.1
    Executable: /home/drako/.local/bin/pyinfra
    Python: 3.8.6 (CPython, GCC 10.2.0)
  • How was pyinfra installed (source/pip)? pyinfra was installed via pip install --local
  • Include pyinfra-debug.log (if one was created)
  File "/home/drako/.local/lib/python3.8/site-packages/pyinfra_cli/main.py", line 216, in cli
    _main(*args, **kwargs)
  File "/home/drako/.local/lib/python3.8/site-packages/pyinfra_cli/main.py", line 507, in _main
    fact_data[fact_key] = get_facts(
  File "/home/drako/.local/lib/python3.8/site-packages/pyinfra/api/facts.py", line 251, in get_facts
    data = fact.process(stdout)
  File "/home/drako/.local/lib/python3.8/site-packages/pyinfra/facts/server.py", line 473, in process
    filename, content = part.strip().split('\n', 1)
ValueError: not enough values to unpack (expected 2, got 1)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Fizzadarcommented, Dec 9, 2020

Now released in v1.3!

1reaction
relaxdiegocommented, Nov 1, 2020

I wonder if uname -n would be a more portable way of getting the hostname than the systemd method.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Steps for resolving the hostname - IBM
Fails, but the hostname is converted to an IP address, The resolution is successful but the host is not reachable or active. See...
Read more >
linux - "Unable to resolve hostname" - how to cleanly change ...
All the solutions I've seen to the 'unable to resolve hostname' message involve modifying /etc/hosts or some similar file and then rebooting the...
Read more >
Hostname is not resolving on server - Red Hat Customer Portal
It is not resolving its local hostname from server i.e (portalepd) , but other hostname and domain name is working fine.
Read more >
Sudo: unable to resolve host explained - Globo.Tech
Usually, this error occurs after changing the hostname of your system. The hostname is the name of your device that the network identifies...
Read more >
Why do I get hostname: Name or service not known error?
If you get an error, edit /etc/hostname and /etc/hosts with a proper hostname. Then aptitude install ssmtp again to get it to install....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found