1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/gitlab_user/tasks/sshkey.yml
patchback[bot] bf185573a6
gitlab_user: add expires_at option (#2450) (#2506)
* gitlab_user: add expires_at option

* Add changelog

* Add integration test

* Add expires_at to addSshKeyToUser function

* password is required if state is set to present

* Check expires_at will not be added to a present ssh key

* add documentation about present ssh key

* add expires_at to unit tests

* Improve documentation

Co-authored-by: Felix Fontein <felix@fontein.de>

* Only pass expires_at to api when it is not None

* Emphasize on SSH public key

* Apply felixfontein suggestion

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 054eb90ae5)

Co-authored-by: Amin Vakil <info@aminvakil.com>
2021-05-14 10:34:47 +02:00

134 lines
4.1 KiB
YAML

####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- name: Create gitlab user with sshkey credentials
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: false
sshkey_name: "{{ gitlab_sshkey_name }}"
sshkey_file: "{{ gitlab_sshkey_file }}"
state: present
register: gitlab_user_sshkey
- name: Check user has been created correctly
assert:
that:
- gitlab_user_sshkey is changed
- name: Create gitlab user again
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: false
sshkey_name: "{{ gitlab_sshkey_name }}"
sshkey_file: "{{ gitlab_sshkey_file }}"
state: present
register: gitlab_user_sshkey_again
- name: Check state is not changed
assert:
that:
- gitlab_user_sshkey_again is not changed
- name: Add expires_at to an already created gitlab user with ssh key
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: false
sshkey_name: "{{ gitlab_sshkey_name }}"
sshkey_file: "{{ gitlab_sshkey_file }}"
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}"
state: present
register: gitlab_user_created_user_sshkey_expires_at
- name: Check expires_at will not be added to a present ssh key
assert:
that:
- gitlab_user_created_user_sshkey_expires_at is not changed
- name: Remove created gitlab user
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
validate_certs: false
state: absent
register: gitlab_user_sshkey_remove
- name: Check user has been removed correctly
assert:
that:
- gitlab_user_sshkey_remove is changed
- name: Create gitlab user with sshkey and expires_at
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: false
sshkey_name: "{{ gitlab_sshkey_name }}"
sshkey_file: "{{ gitlab_sshkey_file }}"
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}"
state: present
register: gitlab_user_sshkey_expires_at
- name: Check user has been created correctly
assert:
that:
- gitlab_user_sshkey_expires_at is changed
- name: Create gitlab user with sshkey and expires_at again
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
password: "{{ gitlab_user_pass }}"
validate_certs: false
sshkey_name: "{{ gitlab_sshkey_name }}"
sshkey_file: "{{ gitlab_sshkey_file }}"
sshkey_expires_at: "{{ gitlab_sshkey_expires_at }}"
state: present
register: gitlab_user_sshkey_expires_at_again
- name: Check state is not changed
assert:
that:
- gitlab_user_sshkey_expires_at_again is not changed
- name: Remove created gitlab user
gitlab_user:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
email: "{{ gitlab_user_email }}"
name: "{{ gitlab_user }}"
username: "{{ gitlab_user }}"
validate_certs: false
state: absent
register: gitlab_user_sshkey_expires_at_remove
- name: Check user has been removed correctly
assert:
that:
- gitlab_user_sshkey_expires_at_remove is changed