-
Notifications
You must be signed in to change notification settings - Fork 495
Description
Describe the Bug
Hetzner cloud nodes return no data for ec2_metadata and ec2_userdata:
$ facter -d ec2_metadata
[2025-11-23 17:02:42.366690 ] INFO Facter - executed with command line: -d ec2_metadata
[2025-11-23 17:02:42.366763 ] DEBUG Facter - Facter version: 4.3.0
[2025-11-23 17:02:42.369161 ] DEBUG Facter::FactManager - Resolving facts sequentially
[2025-11-23 17:02:42.369336 ] DEBUG Facter::FactLoader - Loading all internal facts
[2025-11-23 17:02:42.369454 ] DEBUG Facter::FactLoader - Loading custom facts
[2025-11-23 17:02:42.370322 ] DEBUG Facter::FactLoader - Loading external facts
[2025-11-23 17:02:42.371590 ] DEBUG Facter::QueryParser - List of resolvable facts: [#<Facter::SearchedFact:0x0000ffff7ea7e350 @name="ec2_metadata", @fact_class=Facts::Linux::Ec2Metadata, @user_query="ec2_metadata", @type=:core, @file=nil>]
[2025-11-23 17:02:42.372036 ] DEBUG Facter::Core::Execution::Posix - Executing command: virt-what
[2025-11-23 17:02:42.374386 ] DEBUG Facter::Core::Execution::Posix - Failed while executing 'virt-what': No such file or directory - virt-what
[2025-11-23 17:02:42.374802 ] DEBUG Facter::Core::Execution::Posix - Executing command: vmware -v
[2025-11-23 17:02:42.377546 ] DEBUG Facter::Core::Execution::Posix - Failed while executing 'vmware -v': No such file or directory - vmware
[2025-11-23 17:02:42.377780 ] DEBUG Facter::Core::Execution::Posix - Executing command: virt-what
[2025-11-23 17:02:42.382380 ] DEBUG Facter::Core::Execution::Posix - Failed while executing 'virt-what': No such file or directory - virt-what
[2025-11-23 17:02:42.383165 ] DEBUG Facter::Util::FileHelper - File at: /proc/xen/capabilities is not accessible.
[2025-11-23 17:02:42.383374 ] DEBUG Facter::Core::Execution::Posix - Executing command: ["/usr/sbin/xl", "/usr/sbin/xm"] list
[2025-11-23 17:02:42.387094 ] DEBUG Facter::Resolvers::Xen - Command ["/usr/sbin/xl", "/usr/sbin/xm"] list completed with the following stderr message: sh: 1: [/usr/sbin/xl,: not found
[2025-11-23 17:02:42.387454 ] DEBUG Facter::Core::Execution::Posix - Executing command: lspci
[2025-11-23 17:02:42.419871 ] DEBUG Facter::Resolvers::Ec2 - Querying Ec2 metadata
[2025-11-23 17:02:42.441577 ] DEBUG Facter::Util::Resolvers::Http - Request to http://169.254.169.254/latest/api/token failed with error code 404
[2025-11-23 17:02:42.443604 ] DEBUG Facter::Util::Resolvers::Http - Request to http://169.254.169.254/latest/meta-data/ failed with error code 301
[2025-11-23 17:02:42.445186 ] DEBUG Facter::Util::Resolvers::Http - Request to http://169.254.169.254/latest/user-data/ failed with error code 301
The problem is that the call to http://169.254.169.254/latest/meta-data/ gets a 301 response, which is not consider a successful response in util/resolvers/http.rb.
The issue is the trailing slash, the request is being redirected to http://169.254.169.254/latest/meta-data, which returns the expected data:
$ curl http://169.254.169.254/latest/meta-data
availability-zone
hostname
instance-id
local-ipv4
network-config
private-networks
public-ipv4
public-keys
region
vendor_data
Expected Behavior
A clear and concise description of what you expected to happen.
facter ec2_metadata and facter ec2_userdata should return the expected facts.
Steps to Reproduce
On a Hetzner VM, run facter ec2_metadata or facter ec2_userdata.
Environment
- Version 4.3.0 (I also read the source for the most recent version, it seems unchanged)
- Platform: Debian 12
Additional Context
Just removing the trailing slash (if there is one) makes everything work as expected on Hetzner. I tried this on another cloud service, which didn't care about a trailing slash (or not), so it worked fine. I don't have an AWS node to test on right now, and there are many (cloud) environments, so there is some risk of breakage by just stripping the trailing slash.
--- ec2.rb 2025-11-23 18:53:38.275304442 +0000
+++ ec2-hetzner.rb 2025-11-23 18:53:24.155156485 +0000
@@ -25,7 +25,7 @@
end
def query_for_metadata(url, container)
- metadata = get_data_from(url)
+ metadata = get_data_from(url.chomp('/'))
metadata.each_line do |line|
next if line.empty?
A more thorough fix might be to modify def make_request in util/resolvers/http.rb to follow HTTP redirects. It might be undesirable to permit any redirect. Following redirects could be limited to this narrow case (trailing slash vs no trailing slash).
I'm happy to contribute a patch with any of those solutions. What's the best one?