Custom module parameter type checking ignored on linting

I’ve got an custom module I’m tweaking. It works, but “ansible-lint -vv” is throwing these messages that I’m trying to understand. I’d really appreciate any help with this.

The ansible-lint I’m running is

$ ansible-lint --version
ansible-lint 24.9.2 using ansible-core:2.16.9 ansible-compat:24.9.1 ruamel-yaml:0.18.6 ruamel-yaml-clib:0.2.8

Here are the two message in question.

DEBUG    Type checking ignored for 'symlink' option in task 'mwsdinstall.py' at line 23.
DEBUG    Type checking ignored for 'symlink' option in task 'mwsdinstall.py' at line 71.

Both invocations of that module look like this:

- name: "Invoke mwsdinstall: state: {{ mw_common_sdinstall_state }}; package: {{ mw_common_sdinstall_name }}; version {{ mw_common_sdinstall_version }}"  # noqa name[template]
  mwsdinstall.py:
    state:         "{{ mw_common_sdinstall_state }}"                      # noqa yaml[colons] jinja[spacing]
    name:          "{{ mw_common_sdinstall_name }}"                       # noqa yaml[colons]
    version:       "{{ mw_common_sdinstall_version }}"                    # noqa yaml[colons]
    symlink:       "{{ mw_common_sdinstall_symlink }}"                    # noqa yaml[colons]
    symlink_names: "{{[mw_common_sdinstall_symlink_names] | flatten }}"   # noqa yaml[colons]
    user:          "{{ mw_common_sdinstall_user }}"                       # noqa yaml[colons]
    group:         "{{ mw_common_sdinstall_group }}"                      # noqa yaml[colons]
    appbase:       "{{ mw_common_sdinstall_appbase }}"                    # noqa yaml[colons]
    repobase:      "{{ mw_common_sdinstall_repobase }}"                   # noqa yaml[colons]
    pkgage:        "{{ mw_common_sdinstall_pkgage }}"                     # noqa yaml[colons]
    fallbacks:     "{{ mw_common_sdinstall_fallbacks }}"                  # noqa yaml[colons]
  register: mw_common_sdinstall

{{ mw_common_sdinstall_symlink }}" is defined in the defaults/main.yml for this role:

---
# ./defaults/main.yml
mw_common_sdinstall_state:       present                        # noqa yaml[colons]
mw_common_sdinstall_symlink:     true                           # noqa yaml[colons]
mw_common_sdinstall_symlink_names: ['latest']                   # noqa yaml[colons]
mw_common_sdinstall_user:        "{{ mw_global_ci_usr }}"       # noqa yaml[colons]
mw_common_sdinstall_group:       "{{ mw_global_ci_grp }}"       # noqa yaml[colons]
mw_common_sdinstall_appbase:     "{{ mw_global_appbase }}"      # noqa yaml[colons]
mw_common_sdinstall_repobase:    "{{ mw_global_repobase }}"     # noqa yaml[colons]
mw_common_sdinstall_pkgage:      .pkg_age                       # noqa yaml[colons]
mw_common_sdinstall_fallbacks:   3                              # noqa yaml[colons]

In the mwsdinstall.py module itself, the argspec looks like this:

def main():
    fields = {
        "name":          {"type": "str",  "required": True},
        "version":       {"type": "str",  "required": True},
        "symlink":       {"type": "bool", "default":  True},
        "symlink_names": {"type": "list", "default": ["cur", "-latest"], "elements": "str"},
        "user":          {"type": "str",  "default":  "jenkinsci"},
        "group":         {"type": "str",  "default":  "middleware"},
        "pkgage":        {"type": "str",  "default":  ".pkg_age"},
        "fallbacks":     {"type": "int",  "required": False},
        "appbase":       {"type": "str",  "default":  "/opt/local"},
        "repobase":      {"type": "str",  "default":  "/middleware/software-deploy"},
        "state":         {"type": "str",  "default":  "present", "choices": ["present", "absent", "check"]},
    }

    module = AnsibleModule(argument_spec=fields, supports_check_mode=True)

I notice that symlink is the only bool in my parameters. Is this normal behavior for ansible-lint, or is something more subtle going on? I’m really stumped.

Thanks.

I was curious so I played around with this and found that ansible-lint will show that message in the debug logs if the value cannot be parsed as the expected type and contains jinja template markers {{ }}. If the value does not contain jinja markers, a warning is shown.

So in your case, its unable to parse {{ var }} as a bool. It doesnt actually try to substitute var in, so yea that makes sense.

As for why its just the bool parameter…its not! ansible-lint just quits after it finds one attribute it cant parse. So if you remove that boolean attribute from your module, it should show a similar log message for the next int variable (or maybe the list var, i didnt test with lists)

Heres the ansible-lint code that handles the parsing error. ansible-lint/src/ansiblelint/rules/args.py at a3f8492505b60d4be2c9df973967dca436c0cfa4 · ansible/ansible-lint · GitHub

2 Likes

:eyes: Wow. Thanks so much for digging into this. :compass: