puppetlabs/facter — pull request #375 by jeffmccune (2012-12-12 19:30:21+00:00)
Title: (#17925) Fix ec2_userdata: 404 Not Found Error

Without this patch applied Facter returns the following error message to
the user when no user-data is present in the instance metadata server
when Facter is running on an instance in Amazon AWS EC2.

$ facter ec2_userdata
Could not retrieve ec2_userdata: 404 Not Found

This patch addresses the problem by handling the exception produced from
the HTTP 404 Not Found error. In this circumstance of no user-data
being present, the fact value is not set.

With this patch applied the behavior is as follows:

$ userdata=$(facter ec2_userdata); echo "userdata: [${userdata}]"
userdata: []

And the error is not silently dropped with debugging turned on:

$ facter --debug ec2_userdata
No user-data present at http://169.254.169.254/latest/user-data/: server responded with 404 Not Found
value for ec2_userdata is still nil