title: Ansible gets localhost USER wrong?
body: <p>I'm trying to setup a register i.e check if file exists before executing a task in ansible</p>
  
  <pre><code>- name: check CRAN R script exists
    stat:
      path: "{{ playbook_dir }}/scripts/R/cran.R"
    delegate_to: localhost
    register: cran
  
    tags: r_extras
  </code></pre>
  
  <p>This task is part of the playbook as runs as sudo </p>
  
  <pre><code>- name: installing common apt dependencies, pip python packages as well as java
    hosts: base
    remote_user: "{{ sudo_guy }}"
    roles:
              # need to have non previlidged installer guy
              - make_sw_guy
              # apt-get installation
              - common
  
    become: true
  </code></pre>
  
  <p>when I run playbook like this</p>
  
  <pre><code>ansible-playbook -vvvv -i my_hosts all.yml --tags r_extras
  </code></pre>
  
  <p>I get this error</p>
  
  <pre><code>fatal: [bio_training -&gt; localhost]: FAILED! =&gt; {
      "changed": false, 
      "failed": true, 
      "invocation": {
          "module_name": "stat"
      }, 
      "module_stderr": "sudo: a password is required\n", 
      "module_stdout": "", 
      "msg": "MODULE FAILURE"
  }
  </code></pre>
  
  <p>Because Ansible thinks I'm <code>root</code> .. which seems a bit silly to me, but I might be missing the point?</p>
  
  <p>How to check that local file exists? AND/OR how to get <code>$USER</code> variable of the localhost </p>
  
  <hr>
  
  <p>I can "fix" this problem by adding <code>become_user: $USER</code> but I don't know how to make this generic..</p>