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

Update to var-naming[no-role-prefix] breaks on include_tasks (ansible-lint 6.16.1 using ansible-core:2.14.5) #3453

Closed
bnogaro opened this issue May 16, 2023 · 3 comments · Fixed by #3458
Assignees
Labels

Comments

@bnogaro
Copy link

bnogaro commented May 16, 2023

Summary

On 'ansible.builtin.include_tasks', two infrigements to the var-naming[no-role-prefix] rule are systematically infriged, for vars:

  • __file__
  • __line__

These variables are not defined in my playbook, I guess they are internal include_tasks variables;

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint 6.16.1 using ansible-core:2.14.5 ruamel-yaml:None ruamel-yaml-clib:None
  • ansible installation method: pip
  • ansible-lint installation method: pip
STEPS TO REPRODUCE

Run ansible-lint on a playbook with an include_tasks, either in free-form or with file: filename.yaml, usings vars:

- name: Import task
      ansible.builtin.include_tasks: mytask.yml
      vars:
        role_name_my_var: 'toto'
Desired Behavior

No issue should be raised, as all variables follow the role_prefix rule

Actual Behavior

The following issues are raised:

roles/myrole/tasks/main.yml:XX: var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: __file__)
roles/myrole/tasks/main.yml:XX: var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix.  (vars: __line__)
@bnogaro bnogaro added bug new Triage required labels May 16, 2023
@tomaxsas
Copy link

same here

@nodiscc
Copy link

nodiscc commented May 17, 2023

This is not specific to the include_task module, I am getting this issue/false positive on a task that uses the command module:

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: __file__)
roles/tt_rss/tasks/tt-rss.yml:120 Task/Handler: load/upgrade tt-rss database schema

var-naming[no-role-prefix]: Variables names from within roles should use role_name_ as a prefix. (vars: __line__)
roles/tt_rss/tasks/tt-rss.yml:120 Task/Handler: load/upgrade tt-rss database schema
- name: load/upgrade tt-rss database schema
  become: yes
  become_user: tt-rss
  command:
    cmd: /usr/bin/php {{ tt_rss_install_dir }}/update.php --update-schema=force-yes
  register: tt_rss_db_upgrade
  changed_when: "'Database schema is already at latest version.' not in tt_rss_db_upgrade.stdout"
  ignore_errors: "{{ ansible_check_mode }}"
  vars:
    ansible_remote_tmp: /tmp

@cidrblock cidrblock removed the new Triage required label May 17, 2023
@fanderchan
Copy link

This is related to the "vars:" syntax, which I also encountered today. Here's my example:

- name: Get all parent directories of mysql_data_dir_base
  ansible.builtin.set_fact:
    mysql_data_dir_base_parents: "{{ mysql_data_dir_base | regex_replace('[^/]+/?$', '') | regex_replace('(/[^/]+)/*$', '\\1') | regex_findall('[^/]+') }}"
  vars:
    dir: "{{ mysql_data_dir_base }}"

This bug is not serious and does not affect me, as it can correctly locate the position. Moreover, I eventually found out that this parameter is not needed, reminding me that I should delete it. Haha.

Ndpnt added a commit to OpenTermsArchive/deployment that referenced this issue Jun 7, 2023
Disabled as long as version 6.17 is not used by the ansible lint action on github.

ansible/ansible-lint#3453
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants