Ask Your Question

How do you determine if something is in AWS with facter?

asked 2014-11-29 14:05:32 -0600

Once I upgrade to PE 3.7 and gain access to the ec2 facts from facter 2.3, is there an easy method to turn decisions in hiera on whether or not an instance is in AWS. For instance, imagine if you wanted the aws cli installed on every ec2 instance, but no where else in your environment, what fact is most appropriate/reliable/predictable to do this? In the past I've use a static external fact I stage in our AMI creation called cloudprovider, however that was a mechanism to constrain back ported ec2 facts for use on systems in a VPC. I could continue to use this strategy, but I didn't know if there was a better tool. Possibly ec2metadata?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-07-20 21:25:34 -0600

DarylW gravatar image

Similar to garethr's answer above, you could use a known ec2 fact defined above, and check to see if it has a value or not. Remember that in puppet, undef or '' or false all are false values. Something like this should work

if $ec2_instance_id {
  notify{'This is an AWS instance!':}
  # do AWS specific things here
} else {
  notify{'This is NOT an AWS instance!':}
  # do non-AWS things here

edit flag offensive delete link more

answered 2014-12-01 02:50:07 -0600

garethr gravatar image

Facter has a set of core facts especially for detecting information in EC2 using the metadata service:

Assuming you have facter installed on the machine already try running:

facter | grep ec2

This should hopefully list the relevant facts, any of which could be used for your purpose.

edit flag offensive delete link more


I'm mostly concerned with using a fact in conditional logic for any ec2 instance. Effectively I'd either want a fact with a predictable and consistent value, or logic that can say if $fact_name has a value, then do something else ...

pwattstbd gravatar imagepwattstbd ( 2014-12-01 14:30:09 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-11-29 14:05:32 -0600

Seen: 2,201 times

Last updated: Jul 20 '15