title: Ansible and ForwardAgent for sudo_user
body: <p>Could someone say me, what am I doing wrong? I'm working with Amazon EC2 instance and want to have agent forwarded to user rails, but when I run next task:</p>
  
  <pre><code>- acl: name={{ item }} etype=user entity=rails permissions=rwx state=present
    with_items:
      - "{{ ansible_env.SSH_AUTH_SOCK|dirname }}"
      - "{{ ansible_env.SSH_AUTH_SOCK }}"
    sudo: true
  </code></pre>
  
  <p>I see failed result: </p>
  
  <pre><code>(item=/tmp/ssh-ULvzaZpq2U) =&gt; {"failed": true, "item": "/tmp/ssh-ULvzaZpq2U"}
  msg: path not found or not accessible!
  </code></pre>
  
  <p>When I try to it manually, without ansible, it looks good:</p>
  
  <pre><code>setfacl -m rails:rwx "$SSH_AUTH_SOCK"
  setfacl -m rails:x $(dirname "$SSH_AUTH_SOCK")
  sudo -u rails ssh -T git@github.com //Hi KELiON! You've successfully authenticated, but GitHub does not provide shell access.
  </code></pre>
  
  <p>I even tried to run new instance and run test ansible playbook:</p>
  
  <pre><code>#!/usr/bin/env ansible-playbook
  ---
  - hosts: all
    remote_user: ubuntu
    tasks:
      - user: name=rails
        sudo: true
      - name: Add ssh agent line to sudoers
        lineinfile:
          dest: /etc/sudoers
          state: present
          regexp: SSH_AUTH_SOCK
          line: Defaults env_keep += "SSH_AUTH_SOCK"
        sudo: true
      - acl: name={{ item }} etype=user entity=rails permissions=rwx state=present
        with_items:
          - "{{ ansible_env.SSH_AUTH_SOCK|dirname }}"
          - "{{ ansible_env.SSH_AUTH_SOCK }}"
        sudo: true
      - name: Test that git ssh connection is working.
        command: ssh -T git@github.com
        sudo: true
        sudo_user: rails
  </code></pre>
  
  <p>ansible.cfg is:</p>
  
  <pre><code>[ssh_connection]
  pipelining=True
  ssh_args=-o ForwardAgent=yes -o ControlMaster=auto -o ControlPersist=60s
  
  [defaults]
  sudo_flags=-HE
  hostfile=staging
  </code></pre>
  
  <p>But the same result. Any ideas?</p>