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

Wrong tested file path expansion #2513

Closed
qaxi opened this issue Sep 29, 2022 · 0 comments · Fixed by #2515
Closed

Wrong tested file path expansion #2513

qaxi opened this issue Sep 29, 2022 · 0 comments · Fixed by #2515
Assignees
Labels

Comments

@qaxi
Copy link

qaxi commented Sep 29, 2022

Summary

Wrong tested file path expansion

Issue Type
  • Bug Report
Ansible and Ansible Lint details
# ansible --version
ansible [core 2.13.4]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

# ansible-lint --version
ansible-lint 6.7.0 using ansible 2.13.4
  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.4 LTS
Release:	20.04
Codename:	focal
STEPS TO REPRODUCE

ansible-lint /root/localtestplaybook.yml does not lint file /root/localtestplaybook.yml but /tmp/~/localtestplaybook.yml and fail to test that nonexistent file.
Exception - if you run the command in /root directory it works correctly.

Path rewriting occurs on line 240 https://github.com/ansible/ansible-lint/blob/main/src/ansiblelint/file_utils.py#L240

# cd /tmp
# ansible-lint /root/localtestplaybook.yml
...
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/~/localtestplaybook.yml'

# cd /root
# ansible-lint /root/localtestplaybook.yml
WARNING  Listing 1 violation(s) that are fatal
name: All plays should be named. (name[play])
localtestplaybook.yml:2

Finished with 0 failure(s), 1 warning(s) on 1 files.
Desired Behavior

Read and lint the file on CLI.

# cd /root
# ansible-lint /root/localtestplaybook.yml
WARNING  Listing 1 violation(s) that are fatal
name: All plays should be named. (name[play])
localtestplaybook.yml:2

Finished with 0 failure(s), 1 warning(s) on 1 files.
Actual Behavior

Please give some details of what is actually happening.
Include a minimum complete verifiable example with:

# cd /tmp
#
# cat /root/localtestplaybook.yml <<HERE
---
- hosts: all
  connection: local
  gather_facts: true
  tasks:
    - name: Hello World!
      ansible.builtin.set_fact:
        hello: "Hello World!"

    - name: Print MSG
      ansible.builtin.debug:
        var: "hostvars.{{ inventory_hostname }}"
        verbosity: 1
HERE
#
#
# ansible-lint /root/localtestplaybook.yml
Traceback (most recent call last):
  File "/usr/local/bin/ansible-lint", line 8, in <module>
    sys.exit(_run_cli_entrypoint())
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/__main__.py", line 307, in _run_cli_entrypoint
    sys.exit(main(sys.argv))
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/__main__.py", line 209, in main
    result = _get_matches(rules, options)
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/runner.py", line 226, in _get_matches
    matches.extend(runner.run())
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/runner.py", line 119, in run
    lintable.data
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/file_utils.py", line 347, in data
    self._data = parse_yaml_linenumbers(self)
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/utils.py", line 765, in parse_yaml_linenumbers
    loader = AnsibleLoader(lintable.content, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/file_utils.py", line 273, in content
    self._populate_content_cache_from_disk()
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/file_utils.py", line 265, in _populate_content_cache_from_disk
    raise ex
  File "/usr/local/lib/python3.8/dist-packages/ansiblelint/file_utils.py", line 260, in _populate_content_cache_from_disk
    self._content = self.path.resolve().read_text(encoding="utf-8")
  File "/usr/lib/python3.8/pathlib.py", line 1236, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/usr/lib/python3.8/pathlib.py", line 1222, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "/usr/lib/python3.8/pathlib.py", line 1078, in _opener
    return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/~/localtestplaybook.yml'
ansible-playbook --syntax-check /root/localtestplaybook.yml 
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

playbook: /root/localtestplaybook.yml

@qaxi qaxi added bug new Triage required labels Sep 29, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Sep 29, 2022
@ssbarnea ssbarnea removed the new Triage required label Sep 29, 2022
@ssbarnea ssbarnea self-assigned this Sep 29, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Sep 29, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Sep 29, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Sep 29, 2022
ssbarnea added a commit that referenced this issue Sep 29, 2022
ssbarnea added a commit to ssbarnea/ansible-lint that referenced this issue Oct 5, 2022
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.

2 participants