title: Installing Apache through Ansible
body: <p>I am attempting to install Apache on an EC2 instance through Ansible. My playbook looks like this:</p>
  
  <pre><code># Configure and deploy Apache
  - hosts: localhost
    connection: local
    remote_user: ec2-user
    gather_facts: false
    roles:
      - ec2_apache
      - apache
  </code></pre>
  
  <p>The 'ec2_apache' role provisions an EC2 instance and the first task within the apache/main.yml looks like this:</p>
  
  <pre><code>- name: confirm using the latest Apache server
    become: yes
    become_method: sudo
    yum: 
      name: httpd 
      state: latest
  </code></pre>
  
  <p>However, I am getting the following error:</p>
  
  <pre><code>"module_stderr": "sudo: a password is required\n"
  </code></pre>
  
  <p>I did take a look at: <a href="https://stackoverflow.com/questions/21344777/how-to-switch-a-user-per-task-or-set-of-tasks/22749788#22749788">How to switch a user per task or set of tasks?</a> but it did not seem to resolve my problem.</p>
  
  <p>Because the configuration of the Ec2 instance is in one role and the installation of Apache is in another, did I hork up the security in some way?</p>