-
Notifications
You must be signed in to change notification settings - Fork 24k
Description
SUMMARY
gitlab_runner
module is not idempotent when there are more than 20 runners registered. This is because /runners/all
API endpoint in GitLab returns paginated results by default (20 per page). I think the easiest solution is to add all=True
paramter for this call, python-gitlab
documentation: https://python-gitlab.readthedocs.io/en/stable/api/gitlab.v4.html?highlight=runnermanager#gitlab.v4.objects.RunnerManager.all:
ISSUE TYPE
- Bug Report
COMPONENT NAME
lib/ansible/modules/source_control/gitlab_runner.py
ANSIBLE VERSION
ansible 2.8.0
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.7.3 (default, May 11 2019, 00:45:16) [GCC 8.3.1 20190223 (Red Hat 8.3.1-2)]
CONFIGURATION
OS / ENVIRONMENT
Ansible on localhost (Fedora 29) connecting to local GitLab instance in Docker.
STEPS TO REPRODUCE
- Run GitLab instance on your local machine (for example: http://www.damagehead.com/docker-gitlab/)
- Grab registration token and personal API token and put it in
ANSIBLE_GITLAB_TOKEN
andANSIBLE_RUNNER_REGISTRATION_TOKEN
environment variables - Run two times the following playbook (all tasks are idempotent and run only once)
---
- name: Run on localhost
hosts: 127.0.0.1
connection: local
tasks:
- name: Register new runners
gitlab_runner:
access_level: "not_protected"
api_token: "{{ lookup('env', 'ANSIBLE_GITLAB_TOKEN') }}"
description: "{{ item }}"
registration_token: "{{ lookup('env', 'ANSIBLE_RUNNER_REGISTRATION_TOKEN') }}"
url: http://localhost:10080/
with_sequence: start=1 end=20 format=runner%d
- Increase
end
number to 21, and run playbook two times again
---
- name: Run on localhost
hosts: 127.0.0.1
connection: local
tasks:
- name: Register new runners
gitlab_runner:
access_level: "not_protected"
api_token: "{{ lookup('env', 'ANSIBLE_GITLAB_TOKEN') }}"
description: "{{ item }}"
registration_token: "{{ lookup('env', 'ANSIBLE_RUNNER_REGISTRATION_TOKEN') }}"
url: http://localhost:10080/
with_sequence: start=1 end=21 format=runner%d
EXPECTED RESULTS
There are 21 runners registered, after first run there are no tasks in changed state
ACTUAL RESULTS
The last runner (runner21
) is always in changed state, for each playbook run ansible tries to register new runner21
instance since it is not visible in list returned from .all()
call.
TASK [Register new runners] *******
ok: [127.0.0.1] => (item=runner1)
ok: [127.0.0.1] => (item=runner2)
ok: [127.0.0.1] => (item=runner3)
ok: [127.0.0.1] => (item=runner4)
ok: [127.0.0.1] => (item=runner5)
ok: [127.0.0.1] => (item=runner6)
ok: [127.0.0.1] => (item=runner7)
ok: [127.0.0.1] => (item=runner8)
ok: [127.0.0.1] => (item=runner9)
ok: [127.0.0.1] => (item=runner10)
ok: [127.0.0.1] => (item=runner11)
ok: [127.0.0.1] => (item=runner12)
ok: [127.0.0.1] => (item=runner13)
ok: [127.0.0.1] => (item=runner14)
ok: [127.0.0.1] => (item=runner15)
ok: [127.0.0.1] => (item=runner16)
ok: [127.0.0.1] => (item=runner17)
ok: [127.0.0.1] => (item=runner18)
ok: [127.0.0.1] => (item=runner19)
ok: [127.0.0.1] => (item=runner20)
changed: [127.0.0.1] => (item=runner21)