title: How to run tasks with sudo from ansible in EC2 instance
body: <p>I've been playing around with Ansible a little bit and I'm able to launch my playbook against a vagrant virtual machine, but the problems arise when I try to do the same process in an EC2 instance. I just can't sudo any task:</p>
  
  <pre><code># ansible -i inventory/staging dbservers --sudo -a "apt-get update"
  ubuntu@staging-ansible | FAILED | rc=100 &gt;&gt;
  E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
  E: Unable to lock directory /var/lib/apt/lists/
  E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
  E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
  </code></pre>
  
  <p>Any clue? I can sudo with ssh:</p>
  
  <pre><code># ssh ubuntu@staging-ansible "sudo apt-get update"
  sudo: unable to resolve host ip-10-0-0-61
  Get:1 http://eu-west-1.ec2.archive.ubuntu.com precise Release.gpg [198 B]
  Get:2 http://eu-west-1.ec2.archive.ubuntu.com precise-updates Release.gpg [198 B]
  Get:3 http://security.ubuntu.com precise-security Release.gpg [198 B]
  ...
  </code></pre>