summaryrefslogtreecommitdiff
path: root/ansible/roles/trove-setup/tasks/gitano-admin-setup.yml
blob: c4c3eb27744be06b702ee7452133876a5a78dd7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Depends on:
# - gitano-setup.yml
---
- name: Check if the admin user is configured in gitano (This task can fail)
  shell: su git -c 'ssh git@localhost user' | grep '^'{{ TROVE_ADMIN_USER|regex_replace('(\\W)', '\\\\\\1')|quote}}':'
  register: gitano_admin_user
  changed_when: False
  ignore_errors: True
# If the admin user doesn't exist
- name: Create the admin user
  shell: su git -c 'ssh git@localhost user add '{{ TROVE_ADMIN_USER|quote|quote|quote}}' '{{ TROVE_ADMIN_EMAIL|quote|quote|quote }}' '{{ TROVE_ADMIN_NAME|quote|quote|quote }}
  when: gitano_admin_user|failed

- name: Check if admin user is in trove-admin group in gitano (This task can fail)
  shell: su git -c 'ssh git@localhost as '{{ TROVE_ADMIN_USER|quote|quote|quote }}' whoami' | grep 'trove-admin. Trove-local administration'
  register: gitano_admin_group
  changed_when: False
  ignore_errors: True
# If the admin user is not in the trove-admin group
- name: Add the admin user to the trove-admin group in gitano
  shell: su git -c 'ssh git@localhost group adduser trove-admin '{{ TROVE_ADMIN_USER|quote|quote|quote }}
  when: gitano_admin_group|failed

- name: Check if admin user has a sshkey configured in gitano (This task can fail)
  shell: su git -c 'ssh git@localhost as '{{ TROVE_ADMIN_USER|quote|quote|quote }}' sshkey' 2>&1 | grep WARNING
  register: gitano_admin_key
  changed_when: False
  ignore_errors: True
# If admin user doesn't have an sshkey configured
- name: Create /home/git/keys/ to store sshkeys
  file: path=/home/git/keys state=directory owner=git group=git
  when: gitano_admin_key|success
- name: Copy the TROVE_ADMIN_SSH_PUBKEY to /home/git/keys/admin.key.pub
  copy: src={{ TROVE_ADMIN_SSH_PUBKEY }} dest=/home/git/keys/admin.key.pub mode=0644
  when: gitano_admin_key|success

- name: Add /home/git/keys/admin.key.pub ssh key to the admin user in gitano.
  shell: su git -c 'ssh git@localhost as '{{ TROVE_ADMIN_USER|quote|quote|quote}}' sshkey add default < /home/git/keys/admin.key.pub'
  when: gitano_admin_key|success