# Install packages in recently created EC2 instances

**URL:** <https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125>\
**Category:** Ansible Project\
**Created:** [January 5, 2016, 4:26am UTC](https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125 "2016-01-05T04:26:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Gustavo\_Aguiar](https://forum.ansible.com/u/Gustavo_Aguiar)\
**Post date:** [January 5, 2016, 4:26am UTC](https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125/1 "2016-01-05T04:26:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [January 5, 2016, 6:24am UTC](https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125/2 "2016-01-05T06:24:44Z")

</div>

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](https://github.com/arbabnazar/ansible-aws-vpc-ha-wordpress/blob/master/aws/tasks/webserver.yml#L47)

---

<div class="post-metadata">

**Author:** ![David\_Karban](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@David\_Karban](https://forum.ansible.com/u/David_Karban)\
**Post date:** [January 5, 2016, 10:45am UTC](https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125/3 "2016-01-05T10:45:42Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![Gustavo\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/g/45deac/32.png) [@Gustavo\_Aguiar](https://forum.ansible.com/u/Gustavo_Aguiar)\
**Post date:** [January 5, 2016, 4:46pm UTC](https://forum.ansible.com/t/install-packages-in-recently-created-ec2-instances/20125/4 "2016-01-05T16:46:40Z")

</div>

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!
