Install packages in recently created EC2 instances

Hi All,

I’m trying to install the httpd package in recently created EC2 instances in my playbook.

I have multiple playbooks in different roles that are being invoked at once.

When I get to add my recently created EC2 instances to the also recently created ELB, my registration fails once my instances doesn’t have httpd running yet and the health_check fails.

What would be the best approach in this case ?

  • Installing httpd packages after the EC2 creation and then adding instances to the ELB ?

Thanks in advance,
—Gustavo

You can add the user_data during the ec2 creation like this:

user_data: |
#!/bin/sh
sudo yum install -y httpd

For Complete Reference, please check this link

Hi,

in this case I would first provision web server and join it into ELB after it is fully operational.

Thanks, I think thats a good approach.

Quick not for anyone willing to do the same: user_data already runs as root so you must remove sudo from the command.

user_data: |
#!/bin/sh
yum install httpd -y

Thanks Arbab!