Get root authentication token non-interactively on fresh install

I am dumb, please ignore the everything below the line and if you’re a mod please delete.

What I needed was this page about Sessions which really should be featured first in the API documentation with at least some explicit mention in the summary.

I’m trying to integrate gitlab with some existing systems at my org, and to do so I need to get root’s authentication token so I can then use the API to manage users, groups, etc. However, there is no apparent simple way to do this non-interactively.

I can do the following to get the token spat out in the middle of a bunch of other output:

# echo 'puts User.where(id: 1).first.authentication_token' | gitlab-rails c production | cat
Loading production environment (Rails 4.1.9)
Switch to inspect mode.
puts User.where(id: 1).first.authentication_token

Ok then:

# echo -n 'puts User.where(id: 1).first.authentication_token' | gitlab-rails console production | sed -n 4p

But this is ugly and unreliable at best. Is there a better way?