Skip to main content

Little Timmy will try their best to find those unused and duplicated Ansible variables.

Project description

little-timmy

Little Timmy will try their best to find those unused and duplicated Ansible variables.

cd repo/ansible/plays
ansible-galaxy collection install -f -r requirements.yml -p .
ansible-galaxy role install -f -r requirements.yml -p galaxy_roles

pip3 install little-timmy

little-timmy
# or 
python3 -m little_timmy

It will find

  • Most unused variables in:
    • group_vars
    • host_vars
    • vars
    • defaults
    • set_facts - when not defined as key value pairs on a single line
    • register
    • Inventory files
  • Duplicated variables that have the same value at different group levels.
  • Duplicated variables that have been defined multiple times at the same group level.

It is unlikely to find unused variables or may generate false positives for:

  • Complex, dynamically referenced or created variables
  • Variables referenced by YAML anchors
  • Variables consumed in any custom python filters or similar
  • Non standard(ish) directory layouts

False positives can be ignored with a config file detailed in the Config section.

Please raise issues with any problems, ideas, or contributions with improvements!

Github Action

Workflow

name: little-timmy
on:
  push:
jobs:
  little-timmy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run action
        uses: hoo29/little-timmy@v3-action

Variables

inputs:
  directory:
    description: The root directory for your ansible
    required: false
    default: "."
  additional_cli_args:
    description: Additional CLI arguments to pass to little-timmy
    required: false
    default: ""
  galaxy_role_requirements_file:
    description: Location, relative to `directory`, of the ansible galaxy roles requirements file.
    required: false
  galaxy_collection_requirements_file:
    description: Location, relative to `directory`, of the ansible galaxy collections requirements file.
    required: false
  ansible_vault_password:
    description: |
      Optional ansible-vault password. The content will be a written to a 
      file and ANSIBLE_VAULT_PASSWORD_FILE set to its location. Only used
      by ansible if a vaulted value is found.
    required: false
    default: replace-me-if-vault-is-used

Version and Tags

The latest version can be found in CHANGELOG.md.

The tags on this repo are used for the Github action and do not relate the published python module.

Config

Additional, optional configuration can be specified in a YAML configuration file named .little-timmy. The file can be located at any level between the current working directory and /.

The schema for the file is:

{
    "type": "object",
    "properties": {
        "galaxy_dirs": {
            "description": "Directories where ansible-galaxy collections and roles have been installed. Must be within the directory being scanned.",
            "default": ["ansible_collections", "galaxy_roles"],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "skip_vars": {
            "description": "Variables to skip checking.",
            "default": [],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "skip_vars_duplicates_substrings": {
            "description": "Variables containing these substring will not be checked for duplication. This is in addition to skip_vars.",
            "default": ["pass", "vault"],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "skip_dirs": {
            "description": "Directories to skip loading files from.",
            "default": ["molecule", "venv", "tests"],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "playbook_globs": {
            "description": "Globs where to find playbooks.",
            "default": ["/**/*playbook.y*ml"],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "template_globs": {
            "description": "Globs where to find temlates.",
            "default": ["/**/templates/**/*"],
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "extra_jinja_context_keys": {
            "description": """
            Locations where there is already a jinja context for evaluation e.g. `when` and `assert.that`.
            Does not require module FQCN. Values are added to .config_loader.DEFAULT_JINJA_CONTEXT_KEYS.
            """,
            "default": [],
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    },
    "additionalProperties": False
}

Help

little-timmy -h

usage: little-timmy [OPTIONS] [directory]

Process a directory path

positional arguments:
  directory             The directory to process

options:
  -h, --help            show this help message and exit
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Config file to use. By default it will search all dirs to `/` for .little-timmy
  -d, --dave-mode, --no-dave-mode
                        Make logging work on dave's macbook.
  -du, --duplicated-vars, --no-duplicated-vars
                        Find duplicated variables.
  -e, --exit-success, --no-exit-success
                        Exit 0 when unused vars are found.
  -g, --github-action, --no-github-action
                        Output results for github actions.
  -j, --json-output, --no-json-output
                        Output results as json to stdout. Disables the stderr logger.
  -l LOG_LEVEL, --log-level LOG_LEVEL
                        set the logging level (default: INFO).
  -u, --unused-vars, --no-unused-vars
                        Find unused variables.
  -v, --version, --no-version
                        Output the version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

little_timmy-3.3.3.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

little_timmy-3.3.3-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file little_timmy-3.3.3.tar.gz.

File metadata

  • Download URL: little_timmy-3.3.3.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for little_timmy-3.3.3.tar.gz
Algorithm Hash digest
SHA256 ac120ed0acff2b2d05e9d2a4437292bb97866aa52249c86dee962407a4857280
MD5 5d4c882eee4799663899b401114584a6
BLAKE2b-256 603d0921a70cbe4525d10da2bcfc8bd0de0b5c7f8b35c52aab46d16febc90a55

See more details on using hashes here.

Provenance

The following attestation bundles were made for little_timmy-3.3.3.tar.gz:

Publisher: publish_module.yml on hoo29/little-timmy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file little_timmy-3.3.3-py3-none-any.whl.

File metadata

  • Download URL: little_timmy-3.3.3-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for little_timmy-3.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0e9ded49fc8a26f3bfcd90b7424365d90d9fb2e2e78ea75a35ee9f6c5f44d2a8
MD5 6e5c99f5143c49c53764d6748afa7b21
BLAKE2b-256 3c1b88688183fd090349779fffffbfd605cc4e031ade8464ec81532b9aed51c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for little_timmy-3.3.3-py3-none-any.whl:

Publisher: publish_module.yml on hoo29/little-timmy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page