def install_roles(playbook, settings): rolesdir = os.path.join(os.path.dirname(playbook), "roles") rolesfile = os.path.join(os.path.dirname(playbook), "rolesfile.yml") if not os.path.exists(rolesfile): rolesfile = os.path.join(os.path.dirname(playbook), "rolesfile") if os.path.exists(rolesfile): utils.info("Installing roles: Using rolesfile %s and roles dir %s" % (rolesfile, rolesdir), settings) result = utils.execute(["ansible-galaxy", "install", "-r", rolesfile, "-p", rolesdir]) if result.rc: utils.error("Could not install roles from %s:\n%s" % (rolesdir, result.output)) else: utils.info(u"Roles installed \u2713", settings) else: utils.warn("No roles file found for playbook %s, tried %s and %s.yml" % (playbook, rolesfile, rolesfile), settings)
def install_roles(playbook): rolesdir = os.path.join(os.path.dirname(playbook), "roles") rolesfile = os.path.join(os.path.dirname(playbook), "rolesfile.yml") if not os.path.exists(rolesfile): rolesfile = os.path.join(os.path.dirname(playbook), "rolesfile") if os.path.exists(rolesfile): utils.info("Installing roles: Using rolesfile %s and roles dir %s" % (rolesfile, rolesdir)) result = utils.execute(["ansible-galaxy", "install", "-r", rolesfile, "-p", rolesdir]) if result.rc: utils.error("Could not install roles from %s:\n%s" % (rolesdir, result.output)) else: utils.info(u"Roles installed \u2713") else: utils.warn("No roles file found for playbook %s, tried %s and %s.yml" % (playbook, rolesfile, rolesfile))
def main(): config_dir = AppDirs("ansible-review", "com.github.willthames").user_config_dir default_config_file = os.path.join(config_dir, "config.ini") parser = optparse.OptionParser( "%prog playbook_file|role_file|inventory_file", version="%prog " + __version__) parser.add_option('-c', dest='configfile', default=default_config_file, help="Location of configuration file: [%s]" % default_config_file) parser.add_option('-d', dest='rulesdir', help="Location of standards rules") parser.add_option('-r', dest='lintdir', help="Location of additional lint rules") parser.add_option('-q', dest='log_level', action="store_const", default=logging.WARN, const=logging.ERROR, help="Only output errors") parser.add_option('-s', dest='standards_filter', action='append', help="limit standards to specific names") parser.add_option('-v', dest='log_level', action="store_const", default=logging.WARN, const=logging.INFO, help="Show more verbose output") parser.add_option('-V', dest='vaultpass', help="vault password") options, args = parser.parse_args(sys.argv[1:]) settings = read_config(options.configfile) # Merge CLI options with config options. CLI options override config options. for key, value in settings.__dict__.items(): if not getattr(options, key): setattr(options, key, getattr(settings, key)) if os.path.exists(options.configfile): info("Using configuration file: %s" % options.configfile, options) else: warn("No configuration file found at %s" % options.configfile, options, file=sys.stderr) if not options.rulesdir: rules_dir = os.path.join( resource_filename('ansiblereview', 'examples')) warn("Using example standards found at %s" % rules_dir, options, file=sys.stderr) options.rulesdir = rules_dir if not options.lintdir: lint_dir = os.path.join(options.rulesdir, 'lint-rules') if os.path.exists(lint_dir): warn("Using example lint-rules found at %s" % lint_dir, options, file=sys.stderr) options.lintdir = lint_dir if len(args) == 0: buf = sys.stdin if sys.version_info[0] == 3: """Bypass bytes to unidiff regardless.""" buf = buf.buffer candidates = get_candidates_from_diff(buf) else: candidates = args errors = 0 for filename in candidates: if ':' in filename: (filename, lines) = filename.split(":") else: lines = None candidate = classify(filename, options) if candidate: if candidate.binary: warn("Not reviewing binary file %s" % filename, options) continue if lines: info("Reviewing %s lines %s" % (candidate, lines), options) else: info("Reviewing all of %s" % candidate, options) errors = errors + candidate.review(options, lines) else: info("Couldn't classify file %s" % filename, options) return errors
def main(): config_dir = AppDirs("ansible-review", "com.github.willthames").user_config_dir default_config_file = os.path.join(config_dir, "config.ini") parser = optparse.OptionParser( "%prog playbook_file|role_file|inventory_file", version="%prog " + __version__) parser.add_option('-c', dest='configfile', default=default_config_file, help="Location of configuration file: [%s]" % default_config_file) parser.add_option( '-w', dest='workdir', help= "Dir to look for files, also used to checkout git repo if specified") parser.add_option( '-g', dest='ruleszip', help="Weburl containing zip location of rules i.e from a git repo") parser.add_option('-d', dest='rulesdir', help="Location of standards rules relative if -g used") parser.add_option( '-r', dest='lintdir', help="Location of additional lint rules relative if -g used") parser.add_option('-q', dest='log_level', action="store_const", default=logging.WARN, const=logging.ERROR, help="Only output errors") parser.add_option('-s', dest='standards_filter', action='append', help="limit standards to specific names") parser.add_option('-t', dest='output_type', action="store_const", default="stdout", const="cc", help="Change to Code Climate output type") parser.add_option('-v', dest='log_level', action="store_const", default=logging.WARN, const=logging.INFO, help="Show more verbose output") options, args = parser.parse_args(sys.argv[1:]) settings = read_config(options.configfile) # Merge CLI options with config options. CLI options override config options. for key, value in settings.__dict__.iteritems(): if not getattr(options, key): setattr(options, key, getattr(settings, key)) if options.ruleszip and options.workdir: zipurl = options.ruleszip tlscontext = ssl._create_unverified_context() if zipurl.startswith('http'): zipresp = urlopen(zipurl, context=tlscontext) else: zipresp = open(zipurl, 'r') zfile = ZipFile(io.BytesIO(zipresp.read())) zfile.extractall(options.workdir) if options.workdir: if options.rulesdir and options.ruleszip: rulesdirtmp = glob.glob(options.workdir + "/*/" + options.rulesdir) info("Using standards rules from: %s" % rulesdirtmp[0], options) options.rulesdir = rulesdirtmp[0] else: rulesdirtmp = os.path.join(options.workdir, options.rulesdir) info("Using standards rules from: %s" % rulesdirtmp, options) options.rulesdir = rulesdirtmp if options.lintdir and options.ruleszip: lintdirtmp = glob.glob(options.workdir + "/*/" + options.lintdir) info("Using lint rules from: %s" % lintdirtmp[0], options) options.lintdir = lintdirtmp[0] else: lintdirtmp = os.path.join(options.workdir, options.lintdir) info("Using lint rules from: %s" % lintdirtmp, options) options.lintdir = lintdirtmp if os.path.exists(options.configfile): info("Using configuration file: %s" % options.configfile, options) else: if not options.rulesdir: rules_dir = os.path.join( resource_filename('ansiblereview', 'examples')) warn("Using example standards found at %s" % rules_dir, options, file=sys.stderr) options.rulesdir = rules_dir if not options.lintdir: lint_dir = os.path.join(options.rulesdir, 'lint-rules') if os.path.exists(lint_dir): warn("Using example lint-rules found at %s" % lint_dir, options, file=sys.stderr) options.lintdir = lint_dir if not options.rulesdir and not options.lintdir: warn("No configuration file found at %s" % options.configfile, options, file=sys.stderr) if len(args) == 0: candidates = get_candidates_from_diff(sys.stdin) else: candidates = args errors = 0 for filename in candidates: if ':' in filename: (filename, lines) = filename.split(":") else: lines = None candidate = classify(filename) if candidate: if candidate.binary: warn("Not reviewing binary file %s" % filename, options) continue if lines: info("Reviewing %s lines %s" % (candidate, lines), options) else: info("Reviewing all of %s" % candidate, options) errors = errors + candidate.review(options, lines) else: warn("Couldn't classify file %s" % filename, options) return errors
def main(): config_dir = AppDirs("ansible-review", "com.github.willthames").user_config_dir default_config_file = os.path.join(config_dir, "config.ini") parser = optparse.OptionParser("%prog playbook_file|role_file|inventory_file", version="%prog " + __version__) parser.add_option('-c', dest='configfile', default=default_config_file, help="Location of configuration file: [%s]" % default_config_file) parser.add_option('-d', dest='rulesdir', help="Location of standards rules") parser.add_option('-r', dest='lintdir', help="Location of additional lint rules") parser.add_option('-q', dest='log_level', action="store_const", default=logging.WARN, const=logging.ERROR, help="Only output errors") parser.add_option('-s', dest='standards_filter', action='append', help="limit standards to specific names") parser.add_option('-v', dest='log_level', action="store_const", default=logging.WARN, const=logging.INFO, help="Show more verbose output") options, args = parser.parse_args(sys.argv[1:]) settings = read_config(options.configfile) # Merge CLI options with config options. CLI options override config options. for key, value in settings.__dict__.items(): if not getattr(options, key): setattr(options, key, getattr(settings, key)) if os.path.exists(options.configfile): info("Using configuration file: %s" % options.configfile, options) else: warn("No configuration file found at %s" % options.configfile, options, file=sys.stderr) if not options.rulesdir: rules_dir = os.path.join(resource_filename('ansiblereview', 'examples')) warn("Using example standards found at %s" % rules_dir, options, file=sys.stderr) options.rulesdir = rules_dir if not options.lintdir: lint_dir = os.path.join(options.rulesdir, 'lint-rules') if os.path.exists(lint_dir): warn("Using example lint-rules found at %s" % lint_dir, options, file=sys.stderr) options.lintdir = lint_dir if len(args) == 0: buf = sys.stdin if sys.version_info[0] == 3: """Bypass bytes to unidiff regardless.""" buf = buf.buffer candidates = get_candidates_from_diff(buf) else: candidates = args errors = 0 for filename in candidates: if ':' in filename: (filename, lines) = filename.split(":") else: lines = None candidate = classify(filename) if candidate: if candidate.binary: warn("Not reviewing binary file %s" % filename, options) continue if lines: info("Reviewing %s lines %s" % (candidate, lines), options) else: info("Reviewing all of %s" % candidate, options) errors = errors + candidate.review(options, lines) else: info("Couldn't classify file %s" % filename, options) return errors