- name: Add apt key for apt.dockerproject.org
  become: yes
  become_user: root
  apt_key:
    keyserver: hkp://p80.pool.sks-keyservers.net:80
    id: 58118E89F3A912897C070ADBF76221572C52609D
  tags: [docker]

- name: Add repository apt.dockerproject.org
  become: yes
  become_user: root
  apt_repository:
    repo: deb https://apt.dockerproject.org/repo ubuntu-trusty main
    state: present
    update_cache: yes
  tags: [docker]

- name: Install package docker-engine
  become: yes
  become_user: root
  apt:
    name: docker-engine
    state: latest
  tags: [docker]

- name: Add poscar to docker group
  become: yes
  become_user: root
  user:
    name: poscar
    groups: docker
    append: yes
  tags: [docker]

- name: Add apt key for apt.dockerproject.org
  become: yes
  become_user: root
  apt_key:
    keyserver: hkp://p80.pool.sks-keyservers.net:80
    id: 58118E89F3A912897C070ADBF76221572C52609D
  tags: [docker]

- name: Add repository apt.dockerproject.org
  become: yes
  become_user: root
  apt_repository:
    repo: deb https://apt.dockerproject.org/repo ubuntu-trusty main
    state: present
    update_cache: yes
  tags: [docker]

- name: Install package docker-engine
  become: yes
  become_user: root
  apt:
    name: docker-engine
    state: latest
  tags: [docker]

- name: Add poscar to docker group
  become: yes
  become_user: root
  user:
    name: '{{ansible_ssh_user}}'
    groups: docker
    append: yes
  tags: [docker]

Use ansible_ssh_user for docker user
[docker] Use ansible_ssh_user for docker user
