How to change the computer name on a server configured by Puppet

amazon ec2amazon-cloudformationamazon-web-servicespuppetwindows-server-2008-r2

I am new to Puppet and I'm trying to get Puppet to configure my EC2 instances after they're started from a Cloud Formation Template in AWS. The problem is that all the nodes that get started from the Cloud Formation Template all have the same name (the name from the AMI that the new nodes derive from).

I would love to find a way to have puppet rename the nodes when the nodes start up. (although, as far as I know, a Computer Name change requires reboot, a separate issue…)

If you can point me to some documentation that can help me figure this out or if you have any ideas that would be great. My ultimate goal is to have each EC2 start with a unique name so that I can use New Relic server monitoring to report the different servers.

I ultimately need to achieve this for Linux and Windows Server 2008 R2, but I think I've already gotten the Linux side figured out.

UPDATE:

I spoke with New Relic about the issue and they confirmed that there is no way in New Relic currently to report with something other than the machine name. So approaching the problem from the New Relic side isn't an option just yet.

I also want to avoid having to change the machine name after the machine is created because I don't want to reboot the machine after it spins up.

My ideal option would be to have Cloud Formation be able to generate the new EC2 instances from the AMI, but use a specific machine name during creation (like set the machine name to the instance Id or something).

Best Answer

For new relic, you just need to change your hostname as that is the identifier they use. Hostname changes do not require any restart, not at least for Linux. You can do following in puppet exec:

hostname `ifconfig eth0|grep "inet addr"| awk -F ":" '{print $2}'|awk '{print $1}'`

This will set your hostname as IP address and newrelic can use this as identifier. It would be easier for you too to diagnose issues as they will be shown against IP address of the machine.