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

Crash with duplicate keys #689

Closed
Shm013 opened this issue Mar 4, 2020 · 4 comments
Closed

Crash with duplicate keys #689

Shm013 opened this issue Mar 4, 2020 · 4 comments
Labels

Comments

@Shm013
Copy link

Shm013 commented Mar 4, 2020

Issue Type

  • Bug report

Ansible and Ansible Lint details

ansible 2.9.2
ansible-lint 4.2.0
  • ansible installation method: pip, OS package
  • ansible-lint installation method: pip, OS package

Desired Behaviour

ansible-lint crash when test duplicate dict keys.

Actual Behaviour (Bug report only)

My ansible code
roles/cops.disk-scripts/tasks/file.yml:

---
- name: Create a directory /var/lib/node-exporter if it does not exist
  file:
   path: /var/lib/node-exporter
   state: directory
   owner: root
   group: root
   owner: '0755'

Run command
ansible-lint playbooks/disk-script.yml:

[WARNING]: While constructing a mapping from /home/shm/Documents/projects/ansible-cops/roles/cops.disk-scripts/tasks/file.yml, line 4, column 4, found
a duplicate dict key (owner). Using last defined value only.

Examining playbooks/disk-script.yml of type playbook
Examining roles/cops.disk-scripts/tasks/file.yml of type tasks
[WARNING]: While constructing a mapping from <unicode string>, line 4, column 4, found a duplicate dict key (owner). Using last defined value only.

Traceback (most recent call last):
  File "/home/shm/Documents/projects/ansible-cops/venv/bin/ansible-lint", line 8, in <module>
    sys.exit(main())
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/__main__.py", line 187, in main
    matches.extend(runner.run())
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/__init__.py", line 287, in run
    skip_list=self.skip_list))
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/__init__.py", line 177, in run
    matches.extend(rule.matchtasks(playbookfile, text))
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/__init__.py", line 87, in matchtasks
    yaml = ansiblelint.utils.append_skipped_rules(yaml, text, file['type'])
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/utils.py", line 596, in append_skipped_rules
    yaml_skip = _append_skipped_rules(pyyaml_data, file_text, file_type)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ansiblelint/utils.py", line 607, in _append_skipped_rules
    ruamel_data = yaml.load(file_text)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/main.py", line 343, in load
    return constructor.get_single_data()
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 113, in get_single_data
    return self.construct_document(node)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 123, in construct_document
    for _dummy in generator:
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 1563, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 1469, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 146, in construct_object
    data = self.construct_non_recursive_object(node)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 188, in construct_non_recursive_object
    for _dummy in generator:
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 1563, in construct_yaml_map
    self.construct_mapping(node, data, deep=True)
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 1470, in construct_mapping
    if self.check_mapping_key(node, key_node, maptyp, key, value):
  File "/home/shm/Documents/projects/ansible-cops/venv/lib64/python3.6/site-packages/ruamel/yaml/constructor.py", line 295, in check_mapping_key
    raise DuplicateKeyError(*args)
ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
  in "<unicode string>", line 4, column 4:
       path: /var/lib/node-exporter
       ^ (line: 4)
found duplicate key "owner" with value "0755" (original value: "root")
  in "<unicode string>", line 8, column 4:
       owner: '0755'
       ^ (line: 8)

To suppress this check see:
    http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys

Duplicate keys will become an error in future releases, and are errors
by default when using the new API.
@MarkusTeufelberger
Copy link
Contributor

Probably should return a violation of https://ansible-lint.readthedocs.io/en/latest/default_rules.html#failed-to-load-or-parse-file instead of showing a stacktrace, right?

@Shm013
Copy link
Author

Shm013 commented Jul 28, 2020

Yes, I think so.

@ssbarnea ssbarnea changed the title Crash when duplicate test Crash when duplicate keys Jul 28, 2020
@webknjaz
Copy link
Member

@Shm013 is this still relevant to master? Can you reproduce it with a fresh clone?

@ssbarnea ssbarnea changed the title Crash when duplicate keys Crash with duplicate keys Dec 26, 2020
@ssbarnea ssbarnea added the bug label Dec 26, 2020
@ssbarnea
Copy link
Member

Closing as this will be fixed by #953 -- we should not spend more effort on YAML-specific errors.

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

No branches or pull requests

4 participants