AWS CloudFormation Init and chef-client

Hello All,

I have ami’s that I’m creating from chef scripts, and I would like them to
re-register themselves with my chef server on boot. It looks as though it
ought to be a pretty straightforward thing, but I haven’t seen any examples
out there. All of the examples appear to assume a base image without
chef-client and all it’s goodness. So my question is, what is the minimum
required to have an instance spun up from an ami register and come under
control of chef server? I’d like to stuff that into CloudFormation
UserData and speed up my deployments.

Thanks, again,

  • Michael

Hey Michael,

You can use cfn-init to install the omnibus chef-client, copy the validation.pem from S3 (unless it's pre-baked in your ami), and write a client.rb config file and a first-run.json.

Then you just need a cfn command of 'chef-client -c -j

AWS definitely has some example cfn code to do something like this.

--
Michael F. Weinberg | Director of Operations
http://heavywaterops.com | @heavywaterops

On Mar 17, 2015, at 8:38 AM, Michael Lindsay mlindsay@metrodigi.com wrote:

Hello All,

I have ami's that I'm creating from chef scripts, and I would like them to re-register themselves with my chef server on boot. It looks as though it ought to be a pretty straightforward thing, but I haven't seen any examples out there. All of the examples appear to assume a base image without chef-client and all it's goodness. So my question is, what is the minimum required to have an instance spun up from an ami register and come under control of chef server? I'd like to stuff that into CloudFormation UserData and speed up my deployments.

Thanks, again,

  • Michael

This presentation from re:Invent is a little old (like please don't
install Chef directly from Rubygems anymore in this way), but it's
pretty similar to what you want to do.

Skip to around the 40 minute mark.

  • Julian

On Tue, Mar 17, 2015 at 11:38 AM, Michael Lindsay
mlindsay@metrodigi.com wrote:

Hello All,

I have ami's that I'm creating from chef scripts, and I would like them to
re-register themselves with my chef server on boot. It looks as though it
ought to be a pretty straightforward thing, but I haven't seen any examples
out there. All of the examples appear to assume a base image without
chef-client and all it's goodness. So my question is, what is the minimum
required to have an instance spun up from an ami register and come under
control of chef server? I'd like to stuff that into CloudFormation UserData
and speed up my deployments.

Thanks, again,

  • Michael

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: Julian Dunn's Blog - Commentary on media, technology, and everything in between. * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Michael Lindsay wrote:

what is the minimum required to have an [Amazon EC2] instance
spun up from an ami register and come under control of chef
server?

Such requirements for a virtual machine managed by AWS are no
different than those for any other physical or virtual machine.
Your question might be better asked as, "How does one bootstrap
a node
?" or "How does one bootstrap a node in an unattended
manner
?"

Assuming that you want the new machine to initiate contact with
the Chef server rather than having something on the Chef server
or another chef workstation connect to then new machine and start
the process, you'll need to have chef-client installed on the new
machine and for it to connect to and authenticate with a Chef
server, providing a run list and unique node name. There are
multiple ways to accomplish that.

I perform Chef bootstrapping of CloudFormation-launched EC2
instances by using a combination of CloudInit and the
CloudFormation helper scripts to create a file containing a
copy of the server's chef-validator key, download and install
the applicable chef-client package, and initiate a chef-client
run. I trigger all of that upon first boot by providing user
data
to the machine for CloudInit to read by defining it in
the UserData section of the Properties section of my
instance's definition in my stack template. For Ubuntu machines,
I use one of the Ubuntu-provided AMIs, which have CloudInit
installed. For CentOS, I make my own AMI, starting with a machine
launched from one of the CentOS maintainers' images, enabling the
EPEL repository, installing the cloud-init package, shutting down,
and imaging that machine.

Also, when asking a question on a technical mailing list, putting
your question in the message subject
helps people know what
information you seek and thus makes it more likely that those who
can help will read the body of your message. It also helps other
people who have the same question find the answer later.

References:


Phil Mocek
https://mocek.org
-----BEGIN PGP SIGNATURE-----

iQIcBAEBCgAGBQJVDfGMAAoJECo3+Y/AS212pZwP/0WEYtpZgS4K8AtBqraI+tq2
7LdbGmZHsE1Cs5EkRLimGkSNcG/nAM4b0AdnlBqRtQnk5wyny19ayooY2iNmhsXn
9fLjy1q0HLqUwWNpaPahfscfmWcFLR5H3BqbPkcZMMG6SswITK4u/oiXAPORgx37
CPoc+lwt3JgvHo5B2xEcBW2q6NWwo1nxrdnLFWhvoO0aMSlHOEhpoz6BMdF7o/B2
khtbi8TuomjZtvyOp0zucm/uPv7tj3olB1jYrkESE6UaTZgZKq/Ei5AmBI3fXvcI
/dAqU1YSbinkBFECEfwuXC5jx8+duvkYIyeGxNMTvptP4JhYqkLkfb5EtmQn3iXk
V2pEADzBAdGdurmmTmDLoW+L2psi21sIyXJ8XAb/mKiOhbo/p/9q9QiVQ6GeUk6Z
+YrQIRoBc1zs6btYCO+7hKl7g3p1FHPVz1wUmoLXW7WYumPySdvz1e1jxowFJ47p
zRHUxqy72az0aFtgldqGaUoQvxJj7zbdRhrloFZRdf3u71soAv0ha/UcGmQtdcqW
baYqAjDGG3tlo8J0Z9Z5wCGBxfnHiLX1mmfUPbyrePky7fWuGt20fdA+4fDXwE+s
vCrf51+4pSwg980UtAEidV8IGoC9jRWR4KrMMp7OPZaeIUN1oUD1BgvFlDWXUwCI
hDpMKR14QQ96+eGNZOz3
=eTya
-----END PGP SIGNATURE-----