def yaml_form_rather_than_key_value(candidate, settings): with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: content = parse_yaml_linenumbers(f.read(), candidate.path) errors = [] if content: fileinfo = dict(type=candidate.filetype, path=candidate.path) for task in get_action_tasks(content, fileinfo): normal_form = normalize_task(task, candidate.path) action = normal_form['action']['__ansible_module__'] arguments = normal_form['action']['__ansible_arguments__'] # Cope with `set_fact` where task['set_fact'] is None if not task.get(action): continue if isinstance(task[action], dict): continue # allow skipping based on tag e.g. if using splatting # https://docs.ansible.com/ansible/devel/reference_appendices\ # /faq.html#argsplat-unsafe if 'skip_ansible_lint' in (task.get('tags') or []): continue # strip additional newlines off task[action] if task[action].strip().split() != arguments: errors.append(Error(task['__line__'], "Task arguments appear " "to be in key value rather " "than YAML format")) return Result(candidate.path, errors)
def repeated_names(playbook, settings): with codecs.open(playbook['path'], mode='rb', encoding='utf-8') as f: yaml = parse_yaml_linenumbers(f, playbook['path']) namelines = defaultdict(list) errors = [] if yaml: for task in get_action_tasks(yaml, playbook): if 'name' in task: namelines[task['name']].append(task['__line__']) for (name, lines) in namelines.items(): if len(lines) > 1: errors.append(Error(lines[-1], "Task/handler name %s appears multiple times" % name)) return Result(playbook, errors)
def matchtasks(self, file, text): matches = [] yaml = ansible.utils.parse_yaml(text) if yaml: for task in utils.get_action_tasks(yaml, file): result = self.matchtask(file, task) if result: message = None if isinstance(result, str): message = result taskstr = "Task/Handler: " + ansiblelint.utils.task_to_str(task) matches.append(Match(0, taskstr, file['path'], self, message)) return matches
def matchtasks(self, file, text): matches = [] yaml = ansible.utils.parse_yaml(text) if yaml: for task in utils.get_action_tasks(yaml, file): if 'action' in task: result = self.matchtask(file, task) if result: message = None if isinstance(result, str): message = result taskstr = "Task/Handler: " + ansiblelint.utils.task_to_str(task) matches.append(Match(0, taskstr, file['path'], self, message)) return matches
def matchtasks(self, file, text): matches = [] yaml = ansiblelint.utils.parse_yaml_linenumbers(text) if yaml: for task in utils.get_action_tasks(yaml, file): if 'skip_ansible_lint' in task.get('tags', []): continue if 'action' in task: result = self.matchtask(file, task) if result: message = None if isinstance(result, str): message = result taskstr = "Task/Handler: " + ansiblelint.utils.task_to_str(task) matches.append(Match(task[ansiblelint.utils.LINE_NUMBER_KEY], taskstr, file['path'], self, message)) return matches
def matchtasks(self, file, text): matches = [] yaml = utils.parse_yaml_linenumbers(text) if yaml: for task in utils.get_action_tasks(yaml, file): # An empty `tags` block causes `None` to be returned if # the `or []` is not present - `task.get('tags', [])` # does not suffice. if 'skip_ansible_lint' in (task.get('tags') or []): continue if 'action' in task: result = self.matchtask(file, task) if result: message = None if isinstance(result, string_types): message = result taskstr = "Task/Handler: " + utils.task_to_str(task) matches.append(Match(task[utils.LINE_NUMBER_KEY], taskstr, file['path'], self, message)) return matches
def yaml_form_rather_than_key_value(candidate, settings): with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: content = parse_yaml_linenumbers(f.read(), candidate.path) errors = [] if content: fileinfo = dict(type=candidate.filetype, path=candidate.path) for task in get_action_tasks(content, fileinfo): normal_form = normalize_task(task, candidate.path) action = normal_form['action']['__ansible_module__'] arguments = normal_form['action']['__ansible_arguments__'] # FIXME: This is a bug - perhaps when connection is local # or similar if action not in task: continue if isinstance(task[action], dict): continue if task[action] != ' '.join(arguments): errors.append(Error(task['__line__'], "Task arguments appear " "to be in key value rather " "than YAML format")) return Result(candidate.path, errors)
def yaml_form_rather_than_key_value(candidate, settings): with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: content = parse_yaml_linenumbers(f.read(), candidate.path) errors = [] if content: fileinfo = dict(type=candidate.filetype, path=candidate.path) for task in get_action_tasks(content, fileinfo): normal_form = normalize_task(task, candidate.path) action = normal_form['action']['__ansible_module__'] arguments = normal_form['action']['__ansible_arguments__'] # Cope with `set_fact` where task['set_fact'] is None if not task.get(action): continue if isinstance(task[action], dict): continue # strip additional newlines off task[action] if task[action].strip().split() != arguments: errors.append(Error(task['__line__'], "Task arguments appear " "to be in key value rather " "than YAML format")) return Result(candidate.path, errors)
def yaml_form_rather_than_key_value(candidate, settings): with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: content = parse_yaml_linenumbers(f.read(), candidate.path) errors = [] if content: fileinfo = dict(type=candidate.filetype, path=candidate.path) for task in get_action_tasks(content, fileinfo): normal_form = normalize_task(task, candidate.path) action = normal_form['action']['__ansible_module__'] arguments = normal_form['action']['__ansible_arguments__'] # FIXME: This is a bug - perhaps when connection is local # or similar if action not in task: continue if isinstance(task[action], dict): continue if task[action] != ' '.join(arguments): errors.append( Error( task['__line__'], "Task arguments appear " "to be in key value rather " "than YAML format")) return Result(candidate.path, errors)
def yaml_form_rather_than_key_value(candidate, settings): with codecs.open(candidate.path, mode='rb', encoding='utf-8') as f: content = parse_yaml_linenumbers(f.read(), candidate.path) errors = [] if content: fileinfo = dict(type=candidate.filetype, path=candidate.path) for task in get_action_tasks(content, fileinfo): normal_form = normalize_task(task, candidate.path) action = normal_form['action']['__ansible_module__'] arguments = normal_form['action']['__ansible_arguments__'] # Cope with `set_fact` where task['set_fact'] is None if not task.get(action): continue if isinstance(task[action], dict): continue # strip additional newlines off task[action] if task[action].strip().split() != arguments: errors.append( Error( task['__line__'], "Task arguments appear " "to be in key value rather " "than YAML format")) return Result(candidate.path, errors)