| 1 |
--- |
| 2 |
#################################################################### |
| 3 |
# WARNING: These are designed specifically for Ansible tests # |
| 4 |
# and should not be used as examples of how to write Ansible roles # |
| 5 |
#################################################################### |
| 6 |
|
| 7 |
# Copyright (c) Ansible Project |
| 8 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 9 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 10 |
|
| 11 |
- name: Create gitlab user with sshkey credentials |
| 12 |
gitlab_user: |
| 13 |
api_url: "{{ gitlab_host }}" |
| 14 |
api_token: "{{ gitlab_login_token }}" |
| 15 |
email: "{{ gitlab_user_email }}" |
| 16 |
name: "{{ gitlab_user }}" |
| 17 |
username: "{{ gitlab_user }}" |
| 18 |
password: "{{ gitlab_user_pass }}" |
| 19 |
validate_certs: false |
| 20 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 21 |
sshkey_file: "{{ gitlab_sshkey_file }}" |
| 22 |
state: present |
| 23 |
register: gitlab_user_sshkey |
| 24 |
|
| 25 |
- name: Check user has been created correctly |
| 26 |
assert: |
| 27 |
that: |
| 28 |
- gitlab_user_sshkey is changed |
| 29 |
|
| 30 |
- name: Create gitlab user again |
| 31 |
gitlab_user: |
| 32 |
api_url: "{{ gitlab_host }}" |
| 33 |
api_token: "{{ gitlab_login_token }}" |
| 34 |
email: "{{ gitlab_user_email }}" |
| 35 |
name: "{{ gitlab_user }}" |
| 36 |
username: "{{ gitlab_user }}" |
| 37 |
password: "{{ gitlab_user_pass }}" |
| 38 |
validate_certs: false |
| 39 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 40 |
sshkey_file: "{{ gitlab_sshkey_file }}" |
| 41 |
state: present |
| 42 |
register: gitlab_user_sshkey_again |
| 43 |
|
| 44 |
- name: Check state is not changed |
| 45 |
assert: |
| 46 |
that: |
| 47 |
- gitlab_user_sshkey_again is not changed |
| 48 |
|
| 49 |
- name: Update gitlab user ssh key when key material changes |
| 50 |
gitlab_user: |
| 51 |
api_url: "{{ gitlab_host }}" |
| 52 |
api_token: "{{ gitlab_login_token }}" |
| 53 |
email: "{{ gitlab_user_email }}" |
| 54 |
name: "{{ gitlab_user }}" |
| 55 |
username: "{{ gitlab_user }}" |
| 56 |
password: "{{ gitlab_user_pass }}" |
| 57 |
validate_certs: false |
| 58 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 59 |
sshkey_file: "{{ gitlab_sshkey_file_updated }}" |
| 60 |
sshkey_update_mode: update |
| 61 |
state: present |
| 62 |
register: gitlab_user_sshkey_updated |
| 63 |
|
| 64 |
- name: Check ssh key has been updated |
| 65 |
assert: |
| 66 |
that: |
| 67 |
- gitlab_user_sshkey_updated is changed |
| 68 |
|
| 69 |
- name: Update gitlab user ssh key again |
| 70 |
gitlab_user: |
| 71 |
api_url: "{{ gitlab_host }}" |
| 72 |
api_token: "{{ gitlab_login_token }}" |
| 73 |
email: "{{ gitlab_user_email }}" |
| 74 |
name: "{{ gitlab_user }}" |
| 75 |
username: "{{ gitlab_user }}" |
| 76 |
password: "{{ gitlab_user_pass }}" |
| 77 |
validate_certs: false |
| 78 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 79 |
sshkey_file: "{{ gitlab_sshkey_file_updated }}" |
| 80 |
sshkey_update_mode: update |
| 81 |
state: present |
| 82 |
register: gitlab_user_sshkey_updated_again |
| 83 |
|
| 84 |
- name: Check updated ssh key is idempotent |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- gitlab_user_sshkey_updated_again is not changed |
| 88 |
|
| 89 |
- name: Add expires_at to an already created gitlab user with ssh key |
| 90 |
gitlab_user: |
| 91 |
api_url: "{{ gitlab_host }}" |
| 92 |
api_token: "{{ gitlab_login_token }}" |
| 93 |
email: "{{ gitlab_user_email }}" |
| 94 |
name: "{{ gitlab_user }}" |
| 95 |
username: "{{ gitlab_user }}" |
| 96 |
password: "{{ gitlab_user_pass }}" |
| 97 |
validate_certs: false |
| 98 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 99 |
sshkey_file: "{{ gitlab_sshkey_file_updated }}" |
| 100 |
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}" |
| 101 |
sshkey_update_mode: update |
| 102 |
state: present |
| 103 |
register: gitlab_user_created_user_sshkey_expires_at |
| 104 |
|
| 105 |
- name: Check expires_at will not be added to a present ssh key |
| 106 |
assert: |
| 107 |
that: |
| 108 |
- gitlab_user_created_user_sshkey_expires_at is not changed |
| 109 |
|
| 110 |
- name: Remove created gitlab user |
| 111 |
gitlab_user: |
| 112 |
api_url: "{{ gitlab_host }}" |
| 113 |
api_token: "{{ gitlab_login_token }}" |
| 114 |
email: "{{ gitlab_user_email }}" |
| 115 |
name: "{{ gitlab_user }}" |
| 116 |
username: "{{ gitlab_user }}" |
| 117 |
validate_certs: false |
| 118 |
state: absent |
| 119 |
register: gitlab_user_sshkey_remove |
| 120 |
|
| 121 |
- name: Check user has been removed correctly |
| 122 |
assert: |
| 123 |
that: |
| 124 |
- gitlab_user_sshkey_remove is changed |
| 125 |
|
| 126 |
- name: Create gitlab user with sshkey and expires_at |
| 127 |
gitlab_user: |
| 128 |
api_url: "{{ gitlab_host }}" |
| 129 |
api_token: "{{ gitlab_login_token }}" |
| 130 |
email: "{{ gitlab_user_email }}" |
| 131 |
name: "{{ gitlab_user }}" |
| 132 |
username: "{{ gitlab_user }}" |
| 133 |
password: "{{ gitlab_user_pass }}" |
| 134 |
validate_certs: false |
| 135 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 136 |
sshkey_file: "{{ gitlab_sshkey_file }}" |
| 137 |
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}" |
| 138 |
state: present |
| 139 |
register: gitlab_user_sshkey_expires_at |
| 140 |
|
| 141 |
- name: Check user has been created correctly |
| 142 |
assert: |
| 143 |
that: |
| 144 |
- gitlab_user_sshkey_expires_at is changed |
| 145 |
|
| 146 |
- name: Create gitlab user with sshkey and expires_at again |
| 147 |
gitlab_user: |
| 148 |
api_url: "{{ gitlab_host }}" |
| 149 |
api_token: "{{ gitlab_login_token }}" |
| 150 |
email: "{{ gitlab_user_email }}" |
| 151 |
name: "{{ gitlab_user }}" |
| 152 |
username: "{{ gitlab_user }}" |
| 153 |
password: "{{ gitlab_user_pass }}" |
| 154 |
validate_certs: false |
| 155 |
sshkey_name: "{{ gitlab_sshkey_name }}" |
| 156 |
sshkey_file: "{{ gitlab_sshkey_file }}" |
| 157 |
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}" |
| 158 |
state: present |
| 159 |
register: gitlab_user_sshkey_expires_at_again |
| 160 |
|
| 161 |
- name: Check state is not changed |
| 162 |
assert: |
| 163 |
that: |
| 164 |
- gitlab_user_sshkey_expires_at_again is not changed |
| 165 |
|
| 166 |
- name: Remove created gitlab user |
| 167 |
gitlab_user: |
| 168 |
api_url: "{{ gitlab_host }}" |
| 169 |
api_token: "{{ gitlab_login_token }}" |
| 170 |
email: "{{ gitlab_user_email }}" |
| 171 |
name: "{{ gitlab_user }}" |
| 172 |
username: "{{ gitlab_user }}" |
| 173 |
validate_certs: false |
| 174 |
state: absent |
| 175 |
register: gitlab_user_sshkey_expires_at_remove |
| 176 |
|
| 177 |
- name: Check user has been removed correctly |
| 178 |
assert: |
| 179 |
that: |
| 180 |
- gitlab_user_sshkey_expires_at_remove is changed |