无法从数据库获取 gitlab 运行者注册令牌

nix*_*ind 3 gitlab ansible gitlab-ci gitlab-ci-runner gitlab-omnibus

我正在尝试使用 ansible 完全部署我的 gitlab CICD 堆栈并自动注册运行程序。

我在我的剧本中使用以下任务来获取注册令牌并将其存储在事实中以供我的跑步者进一步注册,正如我在几个教程中看到的那样,我们可以从 gitlab 数据库获取注册令牌。

ansible 剧本任务:

- name: Extract Runner Registration Token directly from Gitlab DB
    become: true
    become_user: gitlab-psql
    vars:
        ansible_ssh_pipelining: true
        query: "SELECT runners_registration_token FROM application_settings ORDER BY id DESC LIMIT 1"
        psql_exec: "/opt/gitlab/embedded/bin/psql"
        gitlab_db_name: "gitlabhq_production"
    shell: '{{ psql_exec }} -h /var/opt/gitlab/postgresql/ -d {{ gitlab_db_name }} -t -A -c "{{ query }}"'
    register: gitlab_runner_registration_token_result
Run Code Online (Sandbox Code Playgroud)

但此任务不会取回任何注册令牌(获取空字符串),因为application_settings表中不存在runners_registration_token列。但是该列存在,但返回的字符串被api 拒绝。runners_registration_token_encryptedrunners_registration_token_encryptedrunner-register

因此,我必须从 gitlab gui(在admin/runners中)复制跑步者注册令牌,将其硬编码到剧本中并再次运行剧本以成功注册堆栈。

有人可以解释一下 gitlab 在哪里存储 GUI 中显示的跑步者注册令牌(我注意到重新启动 gitlab 服务器后它是相同的,它不会改变)?是否绝对不可能自动化 gitlab 运行者注册令牌检索以实现自动运行者非交互式注册?你们知道实现这一目标的正确方法吗?

Joo*_*tse 6

也许在应用程序服务器上使用rails控制台?将以下内容放入 shell 或命令中,在 gitlab 应用程序服务器上运行并捕获输出:

gitlab-rails runner -e production "puts Gitlab::CurrentSettings.current_application_settings.runners_registration_token"
Run Code Online (Sandbox Code Playgroud)

所以对于 Ansible 来说是这样的:

- name: Extract Runner Registration Token directly from Gitlab Rails console
    become: true
    shell: 'gitlab-rails runner -e production "puts Gitlab::CurrentSettings.current_application_settings.runners_registration_token"'
    register: gitlab_runner_registration_token_result
Run Code Online (Sandbox Code Playgroud)