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

jenkins_plugin module has undefined Variable tmp_updates_file on update of plugins #5898

Closed
1 task done
MichaelEBi opened this issue Jan 26, 2023 · 7 comments · Fixed by #6100
Closed
1 task done
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type) traceback web_infrastructure

Comments

@MichaelEBi
Copy link

Summary

When updating plugins in jenkins with module jenkins_plugins we get the following error:

msg": "Cannot load JSON data from the tmp updates file."
"details": "local variable 'tmp_updates_file' referenced before assignment"

The error doesnt happen on old version of ansible. The jenkins-plugin Module code shows that this error code is caused by
#5565

Issue Type

Bug Report

Component Name

jenkins_plugin

Ansible Version

$ ansible --version
ansible [core 2.13.7]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.13 (default, Jun 24 2022, 15:27:57) [GCC 8.5.0 20210514 (Red Hat 8.5.0-13)]
  jinja version = 3.1.2
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /usr/local/lib/python3.8/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 5.8.0 # /usr/share/ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 6.1.0

Configuration

$ ansible-config dump --only-changed

OS / Environment

RHEL 7

Steps to Reproduce

- name: update Jenkins plugins to latest
  jenkins_plugin:
    name: "{{ item.path | basename }}"
    updates_url: "{{ jenkins_updates_url }}"
    state: latest
    jenkins_home: "{{ jenkins_home }}"
    force: yes
    with_dependencies: yes
    url: "https://{{ jenkins_hostname }}:{{ jenkins_https_port }}{{ jenkins_url_prefix }}"
    url_username: "redacted"
    url_password: "{{ jenkins_admin_password }}"
    timeout: "300"
    validate_certs: no
  loop: "{{ installed_plugins.files }}"

Expected Results

I expect No error message. The Jenkins Plugin should be downloaded and updated

Actual Results

full trace
`<REDACTED> (1, b'\\n{"msg": "Cannot load JSON data from the tmp updates file.", "failed": true, "exception": "WARNING: The below traceback may *not* be related to the actual failure.\\\\n  File \\\\"/tmp/ansible_jenkins_plugin_payload_6FcmUB/ansible_jenkins_plugin_payload.zip/ansible_collections/community/general/plugins/modules/jenkins_plugin.py\\\\", line 641, in _download_updates\\\\n", "details": "local variable \\'tmp_updates_file\\' referenced before assignment", "invocation": {"module_args": {"force": true, "owner": "jenkins", "client_key": null, "latest_plugins_url_segments": ["latest"], "group": "jenkins", "use_proxy": true, "unsafe_writes": false, "serole": null, "updates_url": ["https://updates.jenkins.io/dynamic-stable-2.375.1"], "state": "present", "version": "latest", "updates_expiration": 86400, "client_cert": null, "setype": null, "url_username": "redacted", "selevel": null, "force_basic_auth": true, "versioned_plugins_url_segments": ["download/plugins", "plugins"], "http_agent": "ansible-httpget", "use_gssapi": false, "jenkins_home": "/var/lib/jenkins", "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "name": "javax-mail-api", "url": "https://localhost:8443", "seuser": null, "with_dependencies": true, "mode": "0644", "timeout": 300.0, "attributes": null, "validate_certs": false, "update_json_url_segment": ["update-center.json", "updates/update-center.json"]}}}\\n', b'/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (C.UTF-8)\\n')
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_jenkins_plugin_payload_6FcmUB/ansible_jenkins_plugin_payload.zip/ansible_collections/community/general/plugins/modules/jenkins_plugin.py", line 641, in _download_updates
failed: [REDACTED] (item={'uid': 993, 'woth': False, 'mtime': 1672747583.4952004, 'inode': 1610643167, 'isgid': False, 'size': 56, 'roth': True, 'isuid': False, 'isreg': False, 'pw_name': 'jenkins', 'gid': 10080, 'ischr': False, 'wusr': True, 'xoth': True, 'rusr': True, 'nlink': 4, 'issock': False, 'rgrp': True, 'gr_name': 'jenkins', 'path': '/var/lib/jenkins/plugins/javax-mail-api', 'xusr': True, 'atime': 1672747583.4712002, 'isdir': True, 'ctime': 1672747583.4952004, 'isblk': False, 'xgrp': True, 'dev': 64777, 'wgrp': False, 'isfifo': False, 'mode': '0755', 'islnk': False}) => {
    "ansible_loop_var": "item",
    "changed": false,
    "details": "local variable 'tmp_updates_file' referenced before assignment",
    "invocation": {
        "module_args": {
            "attributes": null,
            "client_cert": null,
            "client_key": null,
            "force": true,
            "force_basic_auth": true,
            "group": "jenkins",
            "http_agent": "ansible-httpget",
            "jenkins_home": "/var/lib/jenkins",
            "latest_plugins_url_segments": [
                "latest"
            ],
            "mode": "0644",
            "name": "javax-mail-api",
            "owner": "jenkins",
            "selevel": null,
            "serole": null,
            "setype": null,
            "seuser": null,
            "state": "present",
            "timeout": 300.0,
            "unsafe_writes": false,
            "update_json_url_segment": [
                "update-center.json",
                "updates/update-center.json"
            ],
            "updates_expiration": 86400,
            "updates_url": [
                "https://updates.jenkins.io/dynamic-stable-2.375.1"
            ],
            "url": "https://localhost:8443",
            "url_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "url_username": "redacted",
            "use_gssapi": false,
            "use_proxy": true,
            "validate_certs": false,
            "version": "latest",
            "versioned_plugins_url_segments": [
                "download/plugins",
                "plugins"
            ],
            "with_dependencies": true
        }
    },
    "item": {
        "atime": 1672747583.4712002,
        "ctime": 1672747583.4952004,
        "dev": 64777,
        "gid": 10080,
        "gr_name": "jenkins",
        "inode": 1610643167,
        "isblk": false,
        "ischr": false,
        "isdir": true,
        "isfifo": false,
        "isgid": false,
        "islnk": false,
        "isreg": false,
        "issock": false,
        "isuid": false,
        "mode": "0755",
        "mtime": 1672747583.4952004,
        "nlink": 4,
        "path": "/var/lib/jenkins/plugins/javax-mail-api",
        "pw_name": "jenkins",
        "rgrp": true,
        "roth": true,
        "rusr": true,
        "size": 56,
        "uid": 993,
        "wgrp": false,
        "woth": false,
        "wusr": true,
        "xgrp": true,
        "xoth": true,
        "xusr": true
    },
    "msg": "Cannot load JSON data from the tmp updates file."
}`

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@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
Copy link
Collaborator

cc @jtyr
click here for bot help

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) traceback web_infrastructure labels Jan 26, 2023
@MichaelEBi
Copy link
Author

The error occurs only when the update-center.json is not downloaded because ins this case the the variable is not initialized.
following workaround exists therefore: set updates_expiration to 0 to force download

@felixfontein
Copy link
Collaborator

CC @russoz

@russoz
Copy link
Collaborator

russoz commented Jan 30, 2023

Hi @MichaelEBi thanks for reporting this issue. Into it.

@felixfontein
Copy link
Collaborator

@russoz ping

@felixfontein
Copy link
Collaborator

I created a fix for this in #6100.

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 has_pr module module plugins plugin (any type) traceback web_infrastructure
Projects
None yet
4 participants