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

Scheme forces environment variables to be strings #4364

Open
Hummdis opened this issue Oct 11, 2024 · 0 comments
Open

Scheme forces environment variables to be strings #4364

Hummdis opened this issue Oct 11, 2024 · 0 comments
Labels

Comments

@Hummdis
Copy link

Hummdis commented Oct 11, 2024

Summary

When using the environment: option, the environment variable values passed are required to be in full quotes (string types) when environment variables can be other types, too. Failure to put the values in quotes results in "is not valid under any of the given schemas" error message.

Issue Type

  • Bug Report

OS / ENVIRONMENT

~$ ansible-lint --version
ansible-lint 6.17.2 using ansible-core:2.17.5 ansible-compat:4.1.11 ruamel-yaml:0.17.21 ruamel-yaml-clib:0.2.8
~$
  • ansible installation method: PIP
  • ansible-lint installation method: PIP

STEPS TO REPRODUCE

Simply use the environment: option and pass some variables, such as:

      environment:
        ZYPP_PLUGIN_TIMEOUT: 120
        ZYPP_PLUGIN_SEND_TIMEOUT: 120
        ZYPP_PLUGIN_RECEIVE_TIMEOUT: 120

Desired Behavior

I would expect the scheme to recognize that the environment variable value is an integer, which is correct, rather than a string.

Actual Behavior

What actually happens is that this breaks the pipeline due to the linting error.

~$ ansible-lint package_cache.yaml 
WARNING  Listing 1 violation(s) that are fatal
schema[tasks]: {'name': 'Suse - Building zypper cache', 'community.general.zypper_repository': {'repo': '*', 'runrefresh': True, 'auto_import_keys': True, 'disable_gpg_check': True}, 'environment': {'ZYPP_PLUGIN_TIMEOUT': 120, 'ZYPP_PLUGIN_SEND_TIMEOUT': '120', 'ZYPP_PLUGIN_RECEIVE_TIMEOUT': '120'}} is not valid under any of the given schemas
package_cache.yaml:1  Returned errors will not include exact line numbers, but they will mention
the schema name being used as a tag, like ``schema[playbook]``,
``schema[tasks]``.

This rule is not skippable and stops further processing of the file.

If incorrect schema was picked, you might want to either:

* move the file to standard location, so its file is detected correctly.
* use ``kinds:`` option in linter config to help it pick correct file type.


Read documentation for instructions on how to ignore specific rule violations.

              Rule Violation Summary              
 count tag           profile rule associated tags 
     1 schema[tasks] basic   core                 

Failed: 1 failure(s), 0 warning(s) on 1 files. Last profile that met the validation criteria was 'min'.
~$

Therefore, to pass the linting requirement the values must be quoted, thus turning them into strings. So this:

      environment:
        ZYPP_PLUGIN_TIMEOUT: 120
        ZYPP_PLUGIN_SEND_TIMEOUT: 120
        ZYPP_PLUGIN_RECEIVE_TIMEOUT: 120

Needs to be:

      environment:
        ZYPP_PLUGIN_TIMEOUT: "120"
        ZYPP_PLUGIN_SEND_TIMEOUT: "120"
        ZYPP_PLUGIN_RECEIVE_TIMEOUT: "120"

Which results in:

~$ ansible-lint package_cache.yaml 

Passed: 0 failure(s), 0 warning(s) on 1 files. Last profile that met the validation criteria was 'production'.
~$

Others have reported similar issues.

@Hummdis Hummdis added bug new Triage required labels Oct 11, 2024
@Qalthos Qalthos removed the new Triage required label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Roadmap
Development

No branches or pull requests

2 participants