Commit fe12b5f2 authored by Jean-Marc Le Roux's avatar Jean-Marc Le Roux

Create GitLab users during provisioning.

parent a676e8c1
......@@ -8,10 +8,20 @@ docker_group_members:
nodejs_version: "6.x"
gitlab_bot_webhook_token: "a153b0d18961a9947a63888de405eb40"
gitlab_bot_user:
email: "duralex.sedlex@{{ hostname }}"
password: "duralexsedlex" # FIXME
username: "duralexsedlex"
name: "DuraLex SedLex"
gitlab_admin_email: "admin@{{ hostname }}"
gitlab_admin_password: "adminadmin"
gitlab_bot_webhook_token: "a153b0d18961a9947a63888de405eb40"
gitlab_users:
- email: "{{ gitlab_bot_user.email }}"
password: "{{ gitlab_bot_user.password }}"
username: "{{ gitlab_bot_user.username }}"
name: "{{ gitlab_bot_user.name }}"
pm2_service_enabled: yes
pm2_service_state: started
......
......@@ -4,8 +4,12 @@
"adminEmail": "{{ gitlab_admin_email }}",
"adminPassword": "{{ gitlab_admin_password }}"
},
"webhook": {
"gitlabBot": {
"url": "http://172.17.0.1:3002",
"token": "{{ gitlab_bot_webhook_token }}"
"token": "{{ gitlab_bot_webhook_token }}",
"email": "{{ gitlab_bot_user.email }}",
"password": "{{ gitlab_bot_user.password }}",
"username": "{{ gitlab_bot_user.username }}",
"name": "{{ gitlab_bot_user.name }}"
}
}
---
gitlab_version: 10.1.0-ce.0
gitlab_users:
......@@ -17,3 +17,49 @@
GITLAB_OMNIBUS_CONFIG: "external_url 'https://{{ hostname }}/admin/'; nginx['listen_port'] = 80; nginx['listen_https'] = false"
GITLAB_ROOT_EMAIL: "{{ gitlab_admin_email }}"
GITLAB_ROOT_PASSWORD: "{{ gitlab_admin_password }}"
- name: Check if there is an existing OAuth2 token
stat:
path: /etc/amenda/gitlab_token.json
register: gitlab_oauth2_token_json_file
- name: Get a new OAuth2 token
changed_when: no
uri:
url: "http://127.0.0.1:8000/admin/oauth/token"
body_format: "json"
validate_certs: no
method: POST
body:
grant_type: "password"
username: "{{ gitlab_admin_email }}"
password: "{{ gitlab_admin_password }}"
register: gitlab_oauth2_token_res
when: not gitlab_oauth2_token_json_file.stat.exists
- name: Save the GitLab OAuth2 token in /etc/amenda/gitlab_token.json
copy: content="{{ gitlab_oauth2_token_res.json | to_nice_json }}\n" dest=/etc/amenda/gitlab_token.json
when: not gitlab_oauth2_token_json_file.stat.exists
- name: Set the gitlab_oauth2_token fact
set_fact:
gitlab_oauth2_token: "{{ gitlab_oauth2_token_json_file.stat.exists | ternary(lookup('file', '/etc/amenda/gitlab_token.json') | from_json, gitlab_oauth2_token_res.json) }}"
- name: Create GitLab users
uri:
url: "http://127.0.0.1:8000/admin/api/v4/users"
body_format: "json"
validate_certs: no
method: POST
status_code: [200, 201, 409]
body:
email: "{{ item.email }}"
password: "{{ item.password }}"
username: "{{ item.username }}"
name: "{{ item.name }}"
skip_confirmation: "true"
headers:
Authorization: 'Bearer {{ gitlab_oauth2_token.access_token }}'
with_items: "{{ gitlab_users }}"
register: gitlab_created_user
changed_when: gitlab_created_user.status == 201
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment