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

Random Seed Error was a <class 'ansible.errors.AnsibleError'>, original message: Unexpected templating type error occurred / The only supported seed types are: None, int, float, str, bytes, and bytearray #4298

Closed
tabacha opened this issue Aug 23, 2024 · 1 comment · Fixed by #4315
Labels

Comments

@tabacha
Copy link

tabacha commented Aug 23, 2024

Summary

When I use a radom filter with seed in a variable I get an error. Looks like it was there before in #3769

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 24.7.0 using ansible-core:2.16.10 ansible-compat:24.8.0 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Following Playbook:

- name: Test
  gather_facts: false
  hosts:
    - localhost
  tasks:
    - name: Test1 is okay
      ansible.builtin.debug:
        msg: "{{ 12 | random(seed=inventory_hostname) }}"

    - name: Test2 is wrong
      ansible.builtin.debug:
        msg: "{{ cron_hour_raw }}"
      vars:
        cron_hour_raw: "{{ 12 | random(seed=inventory_hostname) }}"
Desired Behavior

Ansible lint should not find an error at all.

Actual Behavior

Ansible lint should not find an error at the second task

Please give some details of what is happening. Include a [minimum complete
verifiable example] with:

  • minimized playbook to reproduce the error
  • the output of running ansible-lint including the command line used
  • if you're getting a stack trace, also the output of
    ansible-playbook --syntax-check playbook
 ansible-lint -vvvv --offline test.yml
DEBUG    Logging initialized to level 10
INFO     Identified /home/sanders/src/scaleup-ansible as project root due .git directory.
DEBUG    Options: Options(_skip_ansible_syntax_check=False, cache_dir=PosixPath('/home/sanders/.cache/ansible-compat/055948'), colored=True, configured=True, cwd=PosixPath('/home/sanders/src/scaleup-ansible'), display_relative_path=True, exclude_paths=['.cache/', '.github/', 'roles/letsencrypt/docs/partnergate_test.yml', 'roles/fix_letsencrypt_root_ca/tasks/main.yml', 'roles/fix_letsencrypt_root_ca/tasks/remove_cert.yml', 'roles/bareos/tasks/add_repo.yml', 'roles/bareos/tasks/fix_22.yml'], format=None, lintables=['test.yml'], list_rules=False, list_tags=False, write_list=[], parseable=False, quiet=False, rulesdirs=[PosixPath('/home/sanders/.su-ansible-pyenv/lib/python3.12/site-packages/ansiblelint/rules')], skip_list=['comments', 'line-length', 'new-line-at-end-of-file', 'empty-string-compare', 'indentation', 'fqcn'], tags=[], verbosity=4, warn_list=['var-naming'], mock_filters=[], mock_modules=[], mock_roles=[], loop_var_prefix=None, only_builtins_allow_collections=[], only_builtins_allow_modules=[], var_naming_pattern=None, offline=True, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, strict=False, rules={}, profile=None, task_name_prefix='{stem} | ', sarif_file=None, config_file='/home/sanders/src/scaleup-ansible/.ansible-lint', generate_ignore=False, rulesdir=[], use_default_rules=False, version=False, list_profiles=False, ignore_file=None, max_tasks=100, max_block_depth=20, supported_ansible_also=[])
DEBUG    CWD: /home/sanders/src/scaleup-ansible
DEBUG    Logging initialized to level 10
DEBUG    Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
WARNING  Skipped installing old role dependencies due to running in offline mode.
INFO     Adding '--pre' to ansible-galaxy collection install because we detected one collection being sourced from git.
WARNING  Skipped installing collection dependencies due to running in offline mode.
INFO     Set ANSIBLE_LIBRARY=/home/sanders/.cache/ansible-compat/055948/modules:/home/sanders/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/sanders/.cache/ansible-compat/055948/collections:/home/sanders/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections:/home/sanders/.su-ansible-pyenv/lib/python3.12/site-packages:/home/sanders/.cache/ansible-compat/055948/collections:/home/sanders/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections:/home/sanders/.su-ansible-pyenv/lib/python3.12/site-packages
INFO     Set ANSIBLE_ROLES_PATH=/home/sanders/.cache/ansible-compat/055948/roles:roles:/home/sanders/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/sanders/src/scaleup-ansible/roles
DEBUG    Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
DEBUG    Logging initialized to level 10
DEBUG    Effective yamllint rules used: {'anchors': {'level': 'error', 'forbid-undeclared-aliases': True, 'forbid-duplicated-anchors': False, 'forbid-unused-anchors': False}, 'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 1, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'float-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error', 'forbid-duplicated-merge-keys': False}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': {'forbid-implicit-octal': True, 'forbid-explicit-octal': True, 'level': 'error'}, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
WARNING  Skipped installing old role dependencies due to running in offline mode.
INFO     Adding '--pre' to ansible-galaxy collection install because we detected one collection being sourced from git.
WARNING  Skipped installing collection dependencies due to running in offline mode.
INFO     Set ANSIBLE_LIBRARY=/home/sanders/.cache/ansible-compat/055948/modules:/home/sanders/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/sanders/.cache/ansible-compat/055948/collections:/home/sanders/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections:/home/sanders/.su-ansible-pyenv/lib/python3.12/site-packages:/home/sanders/.cache/ansible-compat/055948/collections:/home/sanders/.ansible/collections:/usr/share/ansible/collections:/etc/ansible/collections:/home/sanders/.su-ansible-pyenv/lib/python3.12/site-packages
INFO     Set ANSIBLE_ROLES_PATH=/home/sanders/.cache/ansible-compat/055948/roles:roles:/home/sanders/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/sanders/src/scaleup-ansible/roles
INFO     Executing syntax check on playbook test.yml (0.41s)
DEBUG    Examining test.yml of type playbook
DEBUG    Running rule internal-error
DEBUG    Running rule load-failure
DEBUG    Running rule parser-error
DEBUG    Running rule warning
DEBUG    Running rule yaml
DEBUG    Running rule args
DEBUG    Running rule avoid-implicit
DEBUG    Running rule command-instead-of-module
DEBUG    Running rule command-instead-of-shell
DEBUG    Running rule complexity
DEBUG    Running rule deprecated-bare-vars
DEBUG    Running rule deprecated-local-action
DEBUG    Running rule deprecated-module
DEBUG    Running rule fqcn
DEBUG    Running rule galaxy
DEBUG    Running rule ignore-errors
DEBUG    Running rule inline-env-var
DEBUG    Running rule jinja
DEBUG    NUMBER '12' (prefix='')
DEBUG    VBAR '|' (prefix=' ')
DEBUG    NAME 'random' (prefix=' ')
DEBUG    LPAR '(' (prefix='')
DEBUG    NAME 'seed' (prefix='')
DEBUG    EQUAL '=' (prefix='')
DEBUG    NAME 'inventory_hostname' (prefix='')
DEBUG    RPAR ')' (prefix='')
DEBUG    NEWLINE '\n' (prefix=' ')
DEBUG    ENDMARKER '' (prefix='')
DEBUG    Stop.
DEBUG    NUMBER '12' (prefix='')
DEBUG    VBAR '|' (prefix=' ')
DEBUG    NAME 'random' (prefix=' ')
DEBUG    LPAR '(' (prefix='')
DEBUG    NAME 'seed' (prefix='')
DEBUG    EQUAL '=' (prefix='')
DEBUG    NAME 'inventory_hostname' (prefix='')
DEBUG    RPAR ')' (prefix='')
DEBUG    NEWLINE '\n' (prefix='')
DEBUG    ENDMARKER '' (prefix='')
DEBUG    Stop.
DEBUG    NUMBER '12' (prefix='')
DEBUG    VBAR '|' (prefix=' ')
DEBUG    NAME 'random' (prefix=' ')
DEBUG    LPAR '(' (prefix='')
DEBUG    NAME 'seed' (prefix='')
DEBUG    EQUAL '=' (prefix='')
DEBUG    NAME 'inventory_hostname' (prefix='')
DEBUG    RPAR ')' (prefix='')
DEBUG    NEWLINE '\n' (prefix=' ')
DEBUG    ENDMARKER '' (prefix='')
DEBUG    Stop.
DEBUG    NUMBER '12' (prefix='')
DEBUG    VBAR '|' (prefix=' ')
DEBUG    NAME 'random' (prefix=' ')
DEBUG    LPAR '(' (prefix='')
DEBUG    NAME 'seed' (prefix='')
DEBUG    EQUAL '=' (prefix='')
DEBUG    NAME 'inventory_hostname' (prefix='')
DEBUG    RPAR ')' (prefix='')
DEBUG    NEWLINE '\n' (prefix='')
DEBUG    ENDMARKER '' (prefix='')
DEBUG    Stop.
DEBUG    Running rule key-order
DEBUG    Running rule latest
DEBUG    Running rule literal-compare
DEBUG    Running rule loop-var-prefix
DEBUG    Running rule meta-incorrect
DEBUG    Running rule meta-no-tags
DEBUG    Running rule meta-runtime
DEBUG    Running rule meta-video-links
DEBUG    Running rule name
DEBUG    Running rule no-changed-when
DEBUG    Running rule no-free-form
DEBUG    Running rule no-handler
DEBUG    Running rule no-jinja-when
DEBUG    Running rule no-relative-paths
DEBUG    Running rule no-tabs
DEBUG    Running rule package-latest
DEBUG    Running rule partial-become
DEBUG    Running rule playbook-extension
DEBUG    Running rule risky-file-permissions
DEBUG    Running rule risky-octal
DEBUG    Running rule risky-shell-pipe
DEBUG    Running rule role-name
DEBUG    Running rule run-once
DEBUG    Running rule sanity
DEBUG    Running rule schema
DEBUG    Running rule var-naming
DEBUG    Loading ignores from '.ansible-lint-ignore'
WARNING  Listing 1 violation(s) that are fatal
jinja[invalid]: An unhandled exception occurred while templating '{{ 12 | random(seed=inventory_hostname) }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Unexpected templating type error occurred on ({{ 12 | random(seed=inventory_hostname) }}): The only supported seed types are: None,
int, float, str, bytes, and bytearray.. The only supported seed types are: None,
int, float, str, bytes, and bytearray.
test.yml:12 Task/Handler: Test2 is wrong

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

DEBUG    Determined rule-profile order: {'internal-error': (0, 'min'), 'load-failure': (1, 'min'), 'parser-error': (2, 'min'), 'syntax-check': (3, 'min'), 'command-instead-of-module': (4, 'basic'), 'command-instead-of-shell': (5, 'basic'), 'deprecated-bare-vars': (6, 'basic'), 'deprecated-local-action': (7, 'basic'), 'deprecated-module': (8, 'basic'), 'inline-env-var': (9, 'basic'), 'key-order': (10, 'basic'), 'literal-compare': (11, 'basic'), 'jinja': (12, 'basic'), 'no-free-form': (13, 'basic'), 'no-jinja-when': (14, 'basic'), 'no-tabs': (15, 'basic'), 'partial-become': (16, 'basic'), 'playbook-extension': (17, 'basic'), 'role-name': (18, 'basic'), 'schema': (19, 'basic'), 'name': (20, 'basic'), 'var-naming': (21, 'basic'), 'yaml': (22, 'basic'), 'name': (23, 'moderate'), 'name': (24, 'moderate'), 'name': (25, 'moderate'), 'spell-var-name': (26, 'moderate'), 'avoid-implicit': (27, 'safety'), 'latest': (28, 'safety'), 'package-latest': (29, 'safety'), 'risky-file-permissions': (30, 'safety'), 'risky-octal': (31, 'safety'), 'risky-shell-pipe': (32, 'safety'), 'galaxy': (33, 'shared'), 'ignore-errors': (34, 'shared'), 'layout': (35, 'shared'), 'meta-incorrect': (36, 'shared'), 'meta-no-tags': (37, 'shared'), 'meta-video-links': (38, 'shared'), 'meta-version': (39, 'shared'), 'meta-runtime': (40, 'shared'), 'no-changed-when': (41, 'shared'), 'no-changelog': (42, 'shared'), 'no-handler': (43, 'shared'), 'no-relative-paths': (44, 'shared'), 'max-block-depth': (45, 'shared'), 'max-tasks': (46, 'shared'), 'unsafe-loop': (47, 'shared'), 'avoid-dot-notation': (48, 'production'), 'sanity': (49, 'production'), 'fqcn': (50, 'production'), 'import-task-no-when': (51, 'production'), 'meta-no-dependencies': (52, 'production'), 'single-entry-point': (53, 'production'), 'use-loop': (54, 'production')}
              Rule Violation Summary               
 count tag            profile rule associated tags 
     1 jinja[invalid] basic   formatting           

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

@tabacha tabacha added bug new Triage required labels Aug 23, 2024
@cavcrosby
Copy link
Contributor

I believe this can occur due to some unexpected exception mangling when invoking the template function from src/ansiblelint/rules/jinja.py. Working on a patch; I will make a PR soon for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants