# Installing Apache through Ansible

**URL:** <https://forum.ansible.com/t/installing-apache-through-ansible/21495>\
**Category:** Ansible Project\
**Created:** [May 19, 2016, 5:46pm UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495 "2016-05-19T17:46:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Perry\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Perry\_Hoekstra](https://forum.ansible.com/u/Perry_Hoekstra)\
**Post date:** [May 19, 2016, 5:46pm UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495/1 "2016-05-19T17:46:45Z")

</div>

I am attempting to create an EC2 instance in one role and installing Apache on it in the next role.

The pertinent playbook entry looks like this:

# Configure and deploy Apache

- hosts: localhost  
connection: local  
remote\_user: ec2-user  
gather\_facts: false  
roles:
- ec2\_apache
- apache

The ‘ec2\_apache’ role allocates an ec2 instance and the first task within the apache/main.yml looks like this:

- name: confirm using the latest Apache server  
become: yes  
become\_method: sudo  
yum:  
name: httpd  
state: latest

This is where the error message “sudo: a password is required” is returned which leads me to believe I have somehow horked up with security. When it fails, I can SSH into that newly created EC2 instance and do a 'sudo ls /etc" command.

Thoughts on what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 20, 2016, 4:07pm UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495/2 "2016-05-20T16:07:57Z")

</div>

You need to add the option --ask-become-pass to ansible-playbook or set ask\_become\_pass = true in ansible.cfg or the inventory.

---

<div class="post-metadata">

**Author:** ![Perry\_Hoekstra](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Perry\_Hoekstra](https://forum.ansible.com/u/Perry_Hoekstra)\
**Post date:** [May 20, 2016, 4:44pm UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495/3 "2016-05-20T16:44:30Z")

</div>

Kai:

Thanks for the response but the issue with that solution is this is all dynamic and automated so there would be no person to respond. I have had to do some ENV things in order for each of the processes that need it to see the \*.pem file generated at the beginning of the Ansible process that builds the AWS environment.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 20, 2016, 5:18pm UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495/4 "2016-05-20T17:18:27Z")

</div>

You could set ansible\_become\_pass if you can have the sudo password in clear text or add "ec2-user ALL=(ALL) NOPASSWD:ALL" to your sudoers file.

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [May 21, 2016, 9:30am UTC](https://forum.ansible.com/t/installing-apache-through-ansible/21495/5 "2016-05-21T09:30:14Z")

</div>

Unless I'm reading that wrong (and I may be, still on my first  
coffee), you're applying the apache  
role to 'localhost' - don't you want to run that on the ec2 instance  
that ec2\_apache created instead?
