Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitlab_runner: check mode is throwing an Exception #8854

Open
1 task done
marcandre-larochelle-bell opened this issue Sep 11, 2024 · 2 comments
Open
1 task done

gitlab_runner: check mode is throwing an Exception #8854

marcandre-larochelle-bell opened this issue Sep 11, 2024 · 2 comments
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) traceback

Comments

@marcandre-larochelle-bell
Copy link

marcandre-larochelle-bell commented Sep 11, 2024

Summary

Check mode fails due to a code issue in the module regarding the check mode.

Line 519 expects the object called gitlab_runner.runner_object to be an object, however it receives a boolean due to an assignment in the function create_or_update_runner at line 325, when calling the create_runner function there is check for "check_mode" performed and it returns true at line 346 instead of a proper runner object, which then breaks at line 519.

main where the exception happens

        if gitlab_runner.create_or_update_runner(runner_description, runner_values):
->          module.exit_json(changed=True, runner=gitlab_runner.runner_object._attrs,                                 # Faulty attribute
                             msg="Successfully created or updated the runner %s" % runner_description)

create_or_update_runner function (from line 325 to the end of it)

->          runner = self.create_runner(arguments)                                                                                 # Assignment happens here
            changed = True
        else:
            changed, runner = self.update_runner(self.runner_object, arguments)
            if changed:
                if self._module.check_mode:
                    self._module.exit_json(changed=True, msg="Successfully updated the runner %s" % description)

                try:
                    runner.save()
                except Exception as e:
                    self._module.fail_json(msg="Failed to update runner: %s " % to_native(e))

->      self.runner_object = runner                                                                                                        # And then here
        return changed

create_runner function (see the return performed for the check_mode)

    def create_runner(self, arguments):
        if self._module.check_mode:
->          return True                                                                                                                            # Problematic code

        try:
            if arguments.get('token') is not None:
                runner = self._gitlab.runners.create(arguments)
            elif LooseVersion(gitlab.__version__) < LooseVersion('4.0.0'):
                self._module.fail_json(msg="New runner creation workflow requires python-gitlab 4.0.0 or higher")
            else:
                runner = self._gitlab.user.runners.create(arguments)
        except (gitlab.exceptions.GitlabCreateError) as e:
            self._module.fail_json(msg="Failed to create runner: %s " % to_native(e))

        return runner

Issue Type

Bug Report

Component Name

community.general.gitlab_runner module

Ansible Version

2.13.2

Community.general Version

9.4.0

Configuration

No response

OS / Environment

RHEL 9

Steps to Reproduce

  • Run the community.general.gitlab_runner module in check for the creation of a runner
    • We use the new API token (not the old registration token, but I don't think it matters)

Expected Results

Check mode doesn't fail

Actual Results

Stack trace:

The full traceback is:
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py", line 107, in <module>
    _ansiballz_main()
  File "/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py", line 99, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py", line 47, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.gitlab_runner', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.gitlab_runner', _modlib_path=modlib_path),
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/ansible_community.general.gitlab_runner_payload_ing1rl38/ansible_community.general.gitlab_runner_payload.zip/ansible_collections/community/general/plugins/modules/gitlab_runner.py", line 527, in <module>
  File "/tmp/ansible_community.general.gitlab_runner_payload_ing1rl38/ansible_community.general.gitlab_runner_payload.zip/ansible_collections/community/general/plugins/modules/gitlab_runner.py", line 519, in main
AttributeError: 'bool' object has no attribute '_attrs'
fatal: [<REDACTED> -> localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1726081189.0393121-194-134545082989152/AnsiballZ_gitlab_runner.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.general.plugins.modules.gitlab_runner', init_globals=dict(_module_fqn='ansible_collections.community.general.plugins.modules.gitlab_runner', _modlib_path=modlib_path),\n  File \"<frozen runpy>\", line 226, in run_module\n  File \"<frozen runpy>\", line 98, in _run_module_code\n  File \"<frozen runpy>\", line 88, in _run_code\n  File \"/tmp/ansible_community.general.gitlab_runner_payload_ing1rl38/ansible_community.general.gitlab_runner_payload.zip/ansible_collections/community/general/plugins/modules/gitlab_runner.py\", line 527, in <module>\n  File \"/tmp/ansible_community.general.gitlab_runner_payload_ing1rl38/ansible_community.general.gitlab_runner_payload.zip/ansible_collections/community/general/plugins/modules/gitlab_runner.py\", line 519, in main\nAttributeError: 'bool' object has no attribute '_attrs'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@marcandre-larochelle-bell marcandre-larochelle-bell changed the title Gitlab Runner module check mode isn't working properly community.general.gitlab_runner check mode is throwing an Exception Sep 11, 2024
@ansibullbot
Copy link
Collaborator

Files identified in the description:

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

click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) traceback labels Sep 11, 2024
@russoz russoz changed the title community.general.gitlab_runner check mode is throwing an Exception gitlab_runner: check mode is throwing an Exception Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) traceback
Projects
None yet
Development

No branches or pull requests

2 participants