Example #1
0
def main(args = None):
	opts = docopt.docopt(
		doc = __doc__,
		argv = args)
	try:
		if opts["--no-color"]:
			fckit.disable_colors()
		if opts["--verbose"]:
			fckit.enable_tracing()
		if opts["--directory"]:
			fckit.chdir(opts["--directory"])
		role = Role()
		targets = Targets(
			role = role,
			exclude = opts["--exclude"].split(","),
			warning_flags = opts["--warnings"].split(","),
			repository_url = opts["--repository"])
		for key in opts["TARGETS"]:
			fckit.trace("at %s" % key)
			targets[key].build()
		if os.path.exists(targets["check"].path):
			with open(targets["check"].path, "r") as fp:
				print fckit.magenta(fp.read())
	except fckit.Error as exc:
		raise SystemExit(fckit.red(exc))
Example #2
0
	def __init__(self, preferences = None, profileid = None, manifests = None, path = None):
		# resolve preferences:
		if preferences:
			self.preferences = preferences.get("all", {})
			if profileid:
				self.preferences.update(preferences.get(profileid, {}))
		else:
			self.preferences = {}
		# resolve base directory:
		if path:
			path = fckit.Path(path)
			if os.path.isdir(path):
				dirname = path
				self.filename = None
			else:
				dirname, self.filename = os.path.split(path)
			if dirname:
				fckit.chdir(dirname)
		else:
			self.filename = None
		# resolve manifest:
		if self.filename:
			candidates = {manifest["name"]: (manifest, self.filename)
				for manifest in manifests
					for pattern in manifest["filenames"]
						if fnmatch.fnmatch(self.filename, pattern)}
		else:
			candidates = {manifest["name"]: (manifest, filename)
				for manifest in manifests
					for pattern in reversed(manifest["filenames"])
						for filename in glob.glob(pattern)[:1]}
		if not candidates:
			raise Error("no known manifest found")
		elif len(candidates) > 1:
			raise Error(
				[filename for manifest, filename in candidates.values()],
				"multiple candidate manifests found, use -f to select a manifest")
		self.manifest, self.filename = candidates.values()[0]
		fckit.trace("using %s build stack" % self.manifest["name"])
		if not any(key.startswith("on_") for key in self.manifest):
			raise Error("this build stack is still under development, request support on github")
		self.targets = Targets()
		self.vcs = Vcs()
Example #3
0
def check_syntax(role, helpers):
	"generate a playbook using the role and syntax-check it"
	tmpdir = fckit.mkdir()
	cwd = os.getcwd()
	#print "!! role path=", cwd
	#print "!! playbook path=", tmpdir
	fckit.chdir(tmpdir)
	try:
		# write playbook:
		playbook = [{
			"hosts": "127.0.0.1",
			"connection": "local",
			"roles": [role.name],
		}]
		helpers["marshall"](
			obj = playbook,
			path = os.path.join(tmpdir, "playbook.yml"))
		# write inventory:
		inventory = "localhost ansible_connection=local"
		helpers["marshall"](
			obj = inventory,
			path = os.path.join(tmpdir, "inventory.cfg"),
			extname = ".txt")
		# write configuration:
		config = {
			"defaults": {
				"roles_path": os.path.dirname(cwd),
				"hostfile": "inventory.cfg",
			}
		}
		helpers["marshall"](
			obj = config,
			path = os.path.join(tmpdir, "ansible.cfg"))
		# perform the check:
		fckit.check_call("ansible-playbook", "playbook.yml", "--syntax-check")
		return True
	except:
		return False
	finally:
		fckit.chdir(cwd)
		fckit.remove(tmpdir)
Example #4
0
def main(args=None):
    opts = docopt.docopt(doc=__doc__, argv=args)
    try:
        if opts["--no-color"]:
            fckit.disable_colors()
        if opts["--verbose"]:
            fckit.enable_tracing()
        if opts["--directory"]:
            fckit.chdir(opts["--directory"])
        role = Role()
        targets = Targets(role=role,
                          exclude=opts["--exclude"].split(","),
                          warning_flags=opts["--warnings"].split(","),
                          repository_url=opts["--repository"])
        for key in opts["TARGETS"]:
            fckit.trace("at %s" % key)
            targets[key].build()
        if os.path.exists(targets["check"].path):
            with open(targets["check"].path, "r") as fp:
                print fckit.magenta(fp.read())
    except fckit.Error as exc:
        raise SystemExit(fckit.red(exc))
Example #5
0
def check_syntax(role, helpers):
    "generate a playbook using the role and syntax-check it"
    tmpdir = fckit.mkdir()
    cwd = os.getcwd()
    #print "!! role path=", cwd
    #print "!! playbook path=", tmpdir
    fckit.chdir(tmpdir)
    try:
        # write playbook:
        playbook = [{
            "hosts": "127.0.0.1",
            "connection": "local",
            "roles": [role.name],
        }]
        helpers["marshall"](obj=playbook,
                            path=os.path.join(tmpdir, "playbook.yml"))
        # write inventory:
        inventory = "localhost ansible_connection=local"
        helpers["marshall"](obj=inventory,
                            path=os.path.join(tmpdir, "inventory.cfg"),
                            extname=".txt")
        # write configuration:
        config = {
            "defaults": {
                "roles_path": os.path.dirname(cwd),
                "hostfile": "inventory.cfg",
            }
        }
        helpers["marshall"](obj=config,
                            path=os.path.join(tmpdir, "ansible.cfg"))
        # perform the check:
        fckit.check_call("ansible-playbook", "playbook.yml", "--syntax-check")
        return True
    except:
        return False
    finally:
        fckit.chdir(cwd)
        fckit.remove(tmpdir)
Example #6
0
 def tearDown(self):
     fckit.chdir(self.cwd)
     fckit.remove(self.tmpdir)
Example #7
0
 def setUp(self):
     self.cwd = os.getcwd()
     self.tmpdir = fckit.mkdir()
     fckit.chdir(self.tmpdir)
Example #8
0
	def tearDown(self):
		fckit.chdir(self.cwd)
		fckit.remove(self.tmpdir)
Example #9
0
	def setUp(self):
		self.cwd = os.getcwd()
		self.tmpdir = fckit.mkdir()
		fckit.chdir(self.tmpdir)