Skip to main content

Add your description here

Project description

ansible-lint-custom-strict-naming

PyPI PyPI Python Versions black Downloads

Ansible is a powerful tool for configuration management. But it is difficult to maintain the YAML playbook quality. Variable maintenance is one of the difficult tasks because they can be overwritten unexpectedly, if you don't care about such like precedence and position where variables are defined.

This is a strict rule for variable naming, using ansible-lint. Strict naming rule is useful to avoid name collision and to search defined position.

Rules

var_name_prefix

<role_name>_role__ , <task_name>_tasks__

  • prefix Variables defined in
    <role_name>_role__ roles/<role_name>/tasks/
    <role_name>_tasks__ <not_roles>/**/tasks/
  • In ansible-lint, var-naming[no-role-prefix] require to use <role_name>_ as prefix. But it is not enough to avoid name collision or search defined position. So, I add _role__ or _tasks__ to the prefix.

var__, const__

  • var__ prefix
    • Variables dynamically defined by ansible.builtin.set_fact or register
  • const__ prefix
    • Variables dynamically defined by ansible.builtin.set_fact or register
    • Variables statically defined in such like inventory's vars, group_vars, host_vars and etc.

Vars in tasks/<name>.yml or roles/<name>/tasks/main.yml

  • <name>_role__var__ prefix

    • These variables are dynamically defined in roles/<name>/tasks/main.yml.
  • <name>_role__const__ prefix

    • These variables are defined in roles/<name>/vars/main.yml and shouldn't be changed dynamically.
  • some_role__arg__ prefix

    • These variables are defined by ansible.builtin.include_role's vars key and shouldn't be changed dynamically.
  • some_role__args

    • These variables are defined by ansible.builtin.include_role's vars key and shouldn't be changed dynamically.

    • This is useful when you want to send vars as dict.

      - name: Sample
        ansible.builtin.include_role:
          name: some_role
        vars:
          some_role__args:
            key1: value1
            key2: value2
      

examples

tasks:
  - name: Some task
    ansible.builtin.include_role:
      name: <role_name>
    vars:
      some_role__const__one: value1
      some_role__const__two: value2

Others

Double underscores?

  • Single underscore (_) is used to separate words. Double underscores (__) are used to separate chunks for readability.
  • examples
    • var__send_message__user_id
    • var__send_message__content
    • some_role__const__app_config__name
    • some_role__const__app_config__token
    • some_role__const__app_config__version

Docs

Articles

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

Built Distribution

File details

Details for the file ansible-lint-custom-strict-naming-0.1.6.tar.gz.

File metadata

File hashes

Hashes for ansible-lint-custom-strict-naming-0.1.6.tar.gz
Algorithm Hash digest
SHA256 534ca15a6ad896ed4258183c6cc5fe688bc89b78cbda515f7a2091cc4f581e63
MD5 56d2a5c7c35c233178b16491c79bd3b5
BLAKE2b-256 5238bbc204ddfd8b87690773b4343711d3ce0fcf94de83ca5885ed556ef2d78d

See more details on using hashes here.

File details

Details for the file ansible_lint_custom_strict_naming-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_lint_custom_strict_naming-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 60099d97a7364d629436f2961ab35876f0d82d8769b3658ef4ee14299bf9c4ec
MD5 65b6d5e5d77d00f79b9dfbf3104aaffc
BLAKE2b-256 1921562acace583855d613018949a6836f26274846a6b26b743011f08287a428

See more details on using hashes here.

Supported by

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