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

[WIP] Validate variable names on definition #58062

Open
wants to merge 22 commits into
base: devel
from

Conversation

Projects
None yet
4 participants
@mkrizek
Copy link
Contributor

commented Jun 19, 2019

SUMMARY

Check valid identifiers and reserved names conflicts in time of variables 'arrival'.

TODO

  • integration tests (ci complete)

So far with this PR we validate:

  • set_facts
  • registered vars
  • play vars_prompt
  • play vars
  • play vars_files
  • block vars
  • task vars
  • include_vars
  • extra vars
  • include/import params
  • role (and include_role) params
  • role vars (vars/main.yml)
  • role defaults (defaults/main.yml)
  • playbook host/group vars
  • inventory host/group vars
  • inventory vars
  • facts
  • loop_control.loop_var/loop_control.index_var

Fixes #56042

Supersedes #56509 and #57812

Co-authored-by: Brian Coca bcoca@users.noreply.github.com

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

variables

@mkrizek

This comment has been minimized.

Copy link
Contributor Author

commented Jun 19, 2019

cc @bcoca

Show resolved Hide resolved lib/ansible/utils/vars.py Outdated
@bcoca
Copy link
Member

left a comment

mostly looks good, some minor issues about where to do the filtering (core vs plugins)

@bcoca bcoca removed the needs_triage label Jun 20, 2019

@mkrizek mkrizek force-pushed the mkrizek:validate-variables branch from 2229f92 to 877943a Jun 21, 2019

Show resolved Hide resolved lib/ansible/vars/validation.py Outdated

@mkrizek mkrizek force-pushed the mkrizek:validate-variables branch from 115e2d5 to ce65ab9 Jun 24, 2019

@ansibot ansibot added the stale_ci label Jul 2, 2019

@s-hertel

This comment has been minimized.

Copy link
Contributor

commented Jul 11, 2019

This could be done for adhoc too. That's how I came across it - ansible-playbook was giving me warnings but ansible was not.

@mkrizek

This comment has been minimized.

Copy link
Contributor Author

commented Jul 12, 2019

This could be done for adhoc too. That's how I came across it - ansible-playbook was giving me warnings but ansible was not.

@s-hertel It should be independent on the cli used, trying the following simple tests, works as expected:

h1 ansible_connection=local loop_control=1
$ ansible -m set_fact -a 'register=1' h1
 [WARNING]: Found variable using reserved name: loop_control

 [WARNING]: Found variable using reserved name: register

h1 | SUCCESS => {
    "ansible_facts": {
        "register": "1"
    },
    "changed": false
}
$ ansible -m set_fact -a 'True=1' h1
 [WARNING]: Found variable using reserved name: loop_control

ERROR! Invalid variable name specified in facts: 'The variable name 'True' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores.'

Was there a particular use case you tried that this PR does not cover?

@mkrizek

This comment has been minimized.

Copy link
Contributor Author

commented Jul 12, 2019

As a TODO note to myself: loop_control.loop_var/loop_control.index_var is not covered.

Show resolved Hide resolved lib/ansible/vars/reserved.py Outdated

@ansibot ansibot removed the stale_ci label Jul 12, 2019

mkrizek added some commits Jul 15, 2019

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Jul 16, 2019

@mkrizek This PR was evaluated as a potentially problematic PR for the following reasons:

  • More than 50 changed files.

Such PR can only be merged by human. Contact a Core team member to review this PR on IRC: #ansible-devel on irc.freenode.net

click here for bot help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.