We should add export USER=${ANSIBLE_PLAYBOOK_USER_NAME}, before using gosu to provide USER variable.
export USER=${ANSIBLE_PLAYBOOK_USER_NAME}