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

doesn't find .config/ansible-lint.yml in a git repo #2045

Closed
evgeni opened this issue Mar 25, 2022 · 2 comments · Fixed by #2059
Closed

doesn't find .config/ansible-lint.yml in a git repo #2045

evgeni opened this issue Mar 25, 2022 · 2 comments · Fixed by #2059
Labels

Comments

@evgeni
Copy link
Contributor

evgeni commented Mar 25, 2022

Summary

If executed inside a git repo, ansible-lint doesn't find its config if it's called .config/ansible-lint.yml. .ansible-lint works.

Issue Type
  • Bug Report
Ansible and Ansible Lint details
ansible [core 2.12.3]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/evgeni/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/evgeni/Devel/theforeman/foreman-ansible-modules/venv/lib64/python3.10/site-packages/ansible
  ansible collection location = /home/evgeni/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/evgeni/Devel/theforeman/foreman-ansible-modules/venv/bin/ansible
  python version = 3.10.2 (main, Jan 17 2022, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]
  jinja version = 3.0.3
  libyaml = False

% ansible-lint --version
ansible-lint 6.0.2 using ansible 2.12.3

  • ansible installation method: pip
  • ansible-lint installation method: pip
OS / ENVIRONMENT

Fedora 35, but should be irrelevant

STEPS TO REPRODUCE
$ mkdir /tmp/lint-example
$ cd /tmp/lint-example
$ mkdir .config
$ touch .config/ansible-lint.yml
$ ansible-lint -vvv
Invalid configuration file /tmp/lint-example/.config/ansible-lint.yml
$ git init
Initialized empty Git repository in /tmp/lint-example/.git/
$ ansible-lint -vvv
DEBUG    Logging initialized to level 10
DEBUG    Options: Namespace(cache_dir='/home/evgeni/.cache/ansible-compat/956061', colored=True, configured=True, cwd=PosixPath('/tmp/lint-example'), display_relative_path=True, exclude_paths=['.cache', '.git', '.hg', '.svn', '.tox'], format='rich', lintables=[], listrules=False, listtags=False, write=False, parseable=False, quiet=0, rulesdirs=['/home/evgeni/Devel/theforeman/foreman-ansible-modules/venv/lib64/python3.10/site-packages/ansiblelint/rules'], skip_list=[], tags=[], verbosity=3, warn_list=['experimental', 'role-name'], kinds=[{'jinja2': '**/*.j2'}, {'jinja2': '**/*.j2.*'}, {'text': '**/templates/**/*.*'}, {'inventory': '**/inventory/**.yml'}, {'requirements': '**/meta/requirements.yml'}, {'galaxy': '**/galaxy.yml'}, {'reno': '**/releasenotes/*/*.{yaml,yml}'}, {'playbook': '**/playbooks/*.{yml,yaml}'}, {'playbook': '**/*playbook*.{yml,yaml}'}, {'role': '**/roles/*/'}, {'tasks': '**/tasks/**/*.{yaml,yml}'}, {'handlers': '**/handlers/*.{yaml,yml}'}, {'vars': '**/{host_vars,group_vars,vars,defaults}/**/*.{yaml,yml}'}, {'meta': '**/meta/main.{yaml,yml}'}, {'yaml': '.config/molecule/config.{yaml,yml}'}, {'requirements': '**/molecule/*/{collections,requirements}.{yaml,yml}'}, {'yaml': '**/molecule/*/{base,molecule}.{yaml,yml}'}, {'requirements': '**/requirements.yml'}, {'playbook': '**/molecule/*/*.{yaml,yml}'}, {'yaml': '**/{.ansible-lint,.yamllint}'}, {'yaml': '**/*.{yaml,yml}'}, {'yaml': '**/.*.{yaml,yml}'}], mock_modules=[], mock_roles=[], loop_var_prefix=None, var_naming_pattern=None, offline=None, project_dir='.', extra_vars=None, enable_list=[], skip_action_validation=True, rules={}, progressive=False, rulesdir=[], use_default_rules=False, config_file=None, version=False)
DEBUG    /tmp/lint-example
INFO     Set ANSIBLE_LIBRARY=/home/evgeni/.cache/ansible-compat/956061/modules:/home/evgeni/.ansible/plugins/modules:/usr/share/ansible/plugins/modules
INFO     Set ANSIBLE_COLLECTIONS_PATH=/home/evgeni/.cache/ansible-compat/956061/collections:/home/evgeni/.ansible/collections:/usr/share/ansible/collections
INFO     Set ANSIBLE_ROLES_PATH=/home/evgeni/.cache/ansible-compat/956061/roles:/home/evgeni/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles
DEBUG    Loading rules from /home/evgeni/Devel/theforeman/foreman-ansible-modules/venv/lib64/python3.10/site-packages/ansiblelint/rules
DEBUG    Effective yamllint rules used: {'braces': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'brackets': {'level': 'error', 'forbid': False, 'min-spaces-inside': 0, 'max-spaces-inside': 0, 'min-spaces-inside-empty': -1, 'max-spaces-inside-empty': -1}, 'colons': {'level': 'error', 'max-spaces-before': 0, 'max-spaces-after': 1}, 'commas': {'level': 'error', 'max-spaces-before': 0, 'min-spaces-after': 1, 'max-spaces-after': 1}, 'comments': {'level': 'warning', 'require-starting-space': True, 'ignore-shebangs': True, 'min-spaces-from-content': 1}, 'comments-indentation': False, 'document-end': False, 'document-start': False, 'empty-lines': {'level': 'error', 'max': 2, 'max-start': 0, 'max-end': 0}, 'empty-values': False, 'hyphens': {'level': 'error', 'max-spaces-after': 1}, 'indentation': {'level': 'error', 'spaces': 'consistent', 'indent-sequences': True, 'check-multi-line-strings': False}, 'key-duplicates': {'level': 'error'}, 'key-ordering': False, 'line-length': {'level': 'error', 'max': 160, 'allow-non-breakable-words': True, 'allow-non-breakable-inline-mappings': False}, 'new-line-at-end-of-file': {'level': 'error'}, 'new-lines': {'level': 'error', 'type': 'unix'}, 'octal-values': False, 'quoted-strings': False, 'trailing-spaces': {'level': 'error'}, 'truthy': {'level': 'warning', 'allowed-values': ['true', 'false'], 'check-keys': True}}
INFO     Discovered files to lint using: git ls-files --cached --others --exclude-standard -z
INFO     Excluded removed files using: git ls-files --deleted -z
DEBUG    Examining .config/ansible-lint.yml of type yaml

Desired Behavior

config is found

Actual Behavior

while tail:
for project_filename in project_filenames:
filename = os.path.abspath(os.path.join(parent, project_filename))
if os.path.exists(filename):
return filename
if os.path.exists(os.path.abspath(os.path.join(parent, ".git"))):
# Avoid looking outside .git folders as we do not want end-up
# picking config files from upper level projects if current
# project has no config.
return None
(parent, tail) = os.path.split(parent)

The .git detection happens inside the loop for .ansible-lint and .config/ansible-lint.yml, but should be outside.

@evgeni evgeni added bug new Triage required labels Mar 25, 2022
@ganeshrn
Copy link
Member

@evgeni Thanks for raising the issue. It will be great if do can do a pull request since you have already identified the problem area :-), we will be happy to review it.

@ganeshrn ganeshrn removed the new Triage required label Mar 30, 2022
evgeni added a commit to evgeni/ansible-lint that referenced this issue Apr 1, 2022
@evgeni
Copy link
Contributor Author

evgeni commented Apr 1, 2022

There you go #2059

I could not find any existing tests for the config file handling, so I've not added any new 🤷‍♀️

evgeni added a commit to evgeni/ansible-lint that referenced this issue Apr 1, 2022
try both config names before checking .git

Fixes: ansible#2045
evgeni added a commit to evgeni/ansible-lint that referenced this issue Apr 1, 2022
try both config names before checking .git

The bug was introduced in 64d29ab, but
didn't affect anything until 1013149
added a second possible config file name

Fixes: ansible#2045
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