Ask Your Question

How to bootstrap aws ec2 instances setting hostname?

asked 2015-12-14 03:35:41 -0600

johey gravatar image

updated 2015-12-14 06:38:53 -0600

Trying to solve the chicken-egg problem using puppet-aws module. Simply, how can deploy agents of different node types, having them provisioned by the puppet master correctly? I would like to set a unique hostname within the instance declaration, but that seems not possible. I can provide a template as user-data, but I don't like to duplicate the template file with instance-specific data.

What would be the recommended way of bootstrapping ec2 instances and solving my issue with different node types recognized by the puppet master?

Btw, I am using puppet non-enterprise and the official Amazon RHEL-based AMI. Facter is not installed.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-03-03 03:21:35 -0600

szemlyanoy gravatar image

You can apply user_data from erb template where you can set hostname or whatever you need relying on facts of target host.

edit flag offensive delete link more

answered 2016-03-04 21:43:34 -0600

DarylW gravatar image

You can follow what szemlyanoy suggests and template out some custom userdata.

The way we currently provision our instance with using the default ip-1-2-3-4 based hostname is applying a custom tag to indicate the role, and using a custom fact to read in the tags and create a fact based on each one.

Your problem is bootstrapping, which can be solved by tricking facter into knowing the value for your fact.

if you supply an env variable prepended with FACTER_ it will be interpreted by facter.. e.g.

pi@raspberrypi ~ $ FACTER_foo=bar facter foo
pi@raspberrypi ~ $ facter foo

pi@raspberrypi ~ $

so, you could either have a custom fact that reads your information off of the aws fact, or you could just create a file based fact (inside your module) that's value gets assigned based on the value of the fact. That way you could either create the fact as a part of your userdata, or 'seed' the fact with the FACTER_factname formatwhen you initially call puppet agent -t.

Before you call puppet, you should be sure to set up the configuration after installing puppet but before running puppet agent -t

puppet config set --section agent server <puppetmaster-name>
puppet config set --section agent environment production

If you need any more help with setting this up, feel free to ask.

edit flag offensive delete link more

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: 2015-12-14 03:35:41 -0600

Seen: 683 times

Last updated: Mar 04 '16