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

Basic static type inference #3

Open
jokjr opened this issue May 26, 2021 · 1 comment
Open

Basic static type inference #3

jokjr opened this issue May 26, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@jokjr
Copy link
Contributor

jokjr commented May 26, 2021

While full blown type inference may not be feasible, it should be quite doable to catch at least some basic things, like:

selectattr | length

Where Ansible will complain with something like:

The conditional check 'dbms_postgres_reconfig.results | selectattr('changed'
) | selectattr('restart_required') | length' failed.

The error was: Unexpected templating type error occurred on ({% if dbms_postgres_reconfig.results | selectattr('changed') | selectattr('restart_required') | length %} True {% else %} False {% endif %}
):
object of type 'generator' has no len()

The error appears to be in '/home/vagrant/ansible/roles/dbms/tasks/main.yml': line 124, column
 3, but may\nbe elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
- name: restart postgres if our changes necessitate it 
  ^ here"

Basically we can infer that the selectattr filter is a generator, and that length will not work on a generator, but needs a list.

@jokjr jokjr added the enhancement New feature or request label Oct 6, 2021
@jokjr
Copy link
Contributor Author

jokjr commented Jan 6, 2022

Another blunder that we could spot with this would be

- name: do something
  when: "ansible_distribution == 'Debian' and ansible_distribution_version >= 11"
  ...

which yields

 AnsibleError: Unexpected templating type error occurred on ........ '>=' not supported between instances of 'AnsibleUnsafeText' and 'int'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant