title: How do I run a single ansible task with sudo -E?
body: <p>I know I can run playbooks and tasks with sudo, but is there a way to run sudo with arguments? Specifically, I need to run <code>sudo -E &lt;command&gt;</code> to preserve the environment of the logged-in user.</p>
  
  <p>If this is not possible, are there good workarounds?</p>
  
  <hr>
  
  <p><strong>Edit</strong></p>
  
  <p>Two clarifications:</p>
  
  <ol>
  <li>I'm trying to run with <code>sudo -E</code> just for some tasks, not the whole playbook</li>
  <li>A somewhat convoluted example of what I'm trying to do: I have an ubuntu EC2 instance where the <code>ubuntu</code> user has some hosts configured under <code>~/.ssh/config</code>.  I'd like to use those settings with the ansible git module without necessarily copying them into <code>/root/.ssh</code>, and I'd like to use them to modify a directory not owned by the <code>ubuntu</code> user. For pulling, for instance, one way to do this directly in the shell is to <code>sudo -E git pull</code>. An ideal solution would let me (1) use the ansible git module, (2) allow me to <code>sudo -E</code> for this task, and to <code>sudo</code> without the <code>-E</code> flag for other tasks.</li>
  </ol>