Accessing root API token after headless install

I am installing GitLab onto Ubuntu 16.04 using ansible.

Installation is all working, but post installation I want to use the Gitlab API (CLI wrapper) to automatically create projects, users, import repos e.t.c

I have all these steps working on a running GitLab where I have used the UI to set the root users password and retrieve the API token.

But I can not figure out how to do this during a headless install.

On the running system I retrieve the API token using the following ansible task :

   - name: Get GitLab root user private API token
     shell: curl http://localhost/api/v3/session/ --data-urlencode 'login=root' --data-urlencode 'password=password' | jq --raw-output .private_token
     register: result

When I run this on a new GitLab install, a “401 Unauthorized” is returned.

I’m trying to figure out the post install steps (non UI) I need to follow to get the root API token?

I have the same issue, did you ever figure this out?