Repository: ansible-collections/community.general

Issue:
Delete GitLab runner broken
**OVERVIEW**

Error states that it requires registration_token be defined.

**SUMMARY**

Following the example on https://docs.ansible.com/ansible/latest/collections/community/general/gitlab_runner_module.html shows
```
- name: "Delete runner"
  community.general.gitlab_runner:
    api_url: https://gitlab.example.com/
    api_token: "{{ access_token }}"
    description: Docker Machine t1
    state: absent
```

gives error:
```
TASK [Delete GitLab Runner] ******************************************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: registration_token"}
```


**ISSUE TYPE**

Bug Report

**COMPONENT NAME**

gitlab_runner

**ANSIBLE VERSION**

<!--- Paste verbatim output from "ansible --version" between quotes -->
```
ansible 2.10.5
  config file = /home/shannon/.ansible.cfg
  configured module search path = [u'/home/shannon/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/shannon/.local/lib/python2.7/site-packages/ansible
  executable location = /home/shannon/.local/bin/ansible
  python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
```


**CONFIGURATION**

<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```
HOST_KEY_CHECKING(/home/user1/.ansible.cfg) = False
```


**OS / ENVIRONMENT**

Debian Linux 10 Buster
localhost

**STEPS TO REPRO**

<!--- Paste verbatim output from "ansible-config dump --only-changed" between quotes -->
```
- hosts: localhost
  connection: local
  gather_facts: true

  tasks:
   - name: Delete GitLab Runner
     community.general.gitlab_runner:
       api_url: https://gitlab.example.com/
       api_token: "{{ lookup('env','gitlab_token') }}"
       description: cloudnode1
       state: absent
```
ansible-playbook <playbook>.yml


**EXPECTED RESULTS**

deletes runner

**ACTUAL RESULTS**

<!--- Paste verbatim command output between -->
```
TASK [Delete GitLab Runner] ******************************************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "missing required arguments: registration_token"}
```





Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Files identified in the description:
* [`plugins/modules/source_control/gitlab/gitlab_runner.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/source_control/gitlab/gitlab_runner.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Lunik @SamyCoenen @Shaps @dj-wasabi @marwatk @scodeman @waheedi @zanssa
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
```diff
diff --git a/plugins/modules/source_control/gitlab/gitlab_runner.py b/plugins/modules/source_control/gitlab/gitlab_runner.py
index 8ebd1a3851..9021b906d9 100644
--- a/plugins/modules/source_control/gitlab/gitlab_runner.py
+++ b/plugins/modules/source_control/gitlab/gitlab_runner.py
@@ -55,7 +55,7 @@ options:
   registration_token:
     description:
       - The registration token is used to register new runners.
-    required: True
+      - Required if I(state) is C(present).
     type: str
   owned:
     description:
@@ -309,7 +309,7 @@ def main():
         locked=dict(type='bool', default=False),
         access_level=dict(type='str', default='ref_protected', choices=["not_protected", "ref_protected"]),
         maximum_timeout=dict(type='int', default=3600),
-        registration_token=dict(type='str', required=True),
+        registration_token=dict(type='str'),
         state=dict(type='str', default="present", choices=["absent", "present"]),
     ))
 
@@ -325,6 +325,9 @@ def main():
         required_one_of=[
             ['api_username', 'api_token'],
         ],
+        required_if=[
+            ('state', 'present', ['registration_token']),
+        ],
         supports_check_mode=True,
     )
```
Any idea when your fix might go in @Akasurde ?
@kerrhome I guess as soon as someone turns it into a PR that can get merged.
That seemed easy enough so I just submitted the PR
Only 59 other pull requests waiting ahead of this. :) (playing). Thanks folks.

Resolving patch:
diff --git a/plugins/modules/source_control/gitlab/gitlab_runner.py b/plugins/modules/source_control/gitlab/gitlab_runner.py
--- a/plugins/modules/source_control/gitlab/gitlab_runner.py
+++ b/plugins/modules/source_control/gitlab/gitlab_runner.py
@@ -55,7 +55,7 @@
   registration_token:
     description:
       - The registration token is used to register new runners.
-    required: True
+      - Required if I(state) is C(present).
     type: str
   active:
     description:
@@ -284,7 +284,7 @@ def main():
         locked=dict(type='bool', default=False),
         access_level=dict(type='str', default='ref_protected', choices=["not_protected", "ref_protected"]),
         maximum_timeout=dict(type='int', default=3600),
-        registration_token=dict(type='str', required=True, no_log=True),
+        registration_token=dict(type='str', no_log=True),
         state=dict(type='str', default="present", choices=["absent", "present"]),
     ))
 
@@ -300,6 +300,9 @@ def main():
         required_one_of=[
             ['api_username', 'api_token'],
         ],
+        required_if=[
+            ('state', 'present', ['registration_token']),
+        ],
         supports_check_mode=True,
     )
 


Test patch: