def sync_node(node): """Builds, synchronizes and configures a node. It also injects the ipaddress to the node's config file if not already existent. """ if node.get('dummy') or 'dummy' in node.get('tags', []): lib.print_header("Skipping dummy: {0}".format(env.host)) return False current_node = lib.get_node(node['name']) # Check if node locked if solo.node_locked(current_node): content = json.loads(solo.get_lock_info(current_node)) print colors.yellow("Skipping node {0}.\nLocked by {1}.\nReason: {2}".format(current_node['host_name'], content['author'], content['reason'])) return False # Always configure Chef Solo solo.configure(current_node) ipaddress = _get_ipaddress(node) # Everything was configured alright, so save the node configuration # This is done without credentials, so that we keep the node name used # by the user and not the hostname or IP translated by .ssh/config filepath = save_config(node, ipaddress) try: # Synchronize the kitchen directory _synchronize_node(filepath, node) # Execute Chef Solo _configure_node(node) finally: _node_cleanup() return True
def lock_node(node, reason): """"Calls locker with settings,current_node and action variables""" current_node = lib.get_node(node['name']) if solo.node_locked(current_node): content = json.loads(solo.get_lock_info(current_node)) print colors.yellow("Node {0} already locked by {1}.\nReason: {2}".format(current_node['host_name'], content['author'], content['reason'])) raise SystemExit else: solo.lock(current_node, reason) print colors.green("Node {0} locked".format(current_node['host_name'])) record_chef_run(node, "successful", reason)
def print_recipe(recipe): """Pretty prints the given recipe""" print(colors.yellow("\n{0}".format(recipe['name']))) print " description: {0}".format(recipe['description']) print " version: {0}".format(recipe['version']) print " dependencies: {0}".format(", ".join(recipe['dependencies'])) print " attributes: {0}".format(", ".join(recipe['attributes']))
def print_recipe(recipe): """Pretty prints the given recipe""" print (colors.yellow("\n{0}".format(recipe["name"]))) print " description: {0}".format(recipe["description"]) print " version: {0}".format(recipe["version"]) print " dependencies: {0}".format(", ".join(recipe["dependencies"])) print " attributes: {0}".format(", ".join(recipe["attributes"]))
def print_role(role, detailed=True): """Pretty prints the given role""" if detailed: print(colors.yellow(role.get('fullname'))) else: print(" Role: {0}".format(role.get('fullname'))) if detailed: print(" description: {0}".format(role.get('description'))) if 'default_attributes' in role: print(" default_attributes:") _pprint(role['default_attributes']) if 'override_attributes' in role: print(" override_attributes:") _pprint(role['override_attributes']) if detailed: print(" run_list: {0}".format(role.get('run_list'))) print("")
def print_role(role, detailed=True): """Pretty prints the given role""" if detailed: print (colors.yellow(role.get("fullname"))) else: print (" Role: {0}".format(role.get("fullname"))) if detailed: print (" description: {0}".format(role.get("description"))) if "default_attributes" in role: print (" default_attributes:") _pprint(role["default_attributes"]) if "override_attributes" in role: print (" override_attributes:") _pprint(role["override_attributes"]) if detailed: print (" run_list: {0}".format(role.get("run_list"))) print ("")
def print_node(node, detailed=False): """Pretty prints the given node""" nodename = node['name'] print(colors.yellow("\n" + nodename)) # Roles if detailed: for role in get_roles_in_node(node): print_role(_get_role(role), detailed=False) else: print(' Roles: {0}'.format(", ".join(get_roles_in_node(node)))) # Recipes if detailed: for recipe in get_recipes_in_node(node): print " Recipe:", recipe print " attributes: {0}".format(node.get(recipe, "")) else: print(' Recipes: {0}'.format(", ".join(get_recipes_in_node(node)))) # Node attributes print " Node attributes:" for attribute in node.keys(): if attribute == "run_list" or attribute == "name": continue print " {0}: {1}".format(attribute, node[attribute])
def print_node(node, detailed=False): """Pretty prints the given node""" nodename = node["name"] print (colors.yellow("\n" + nodename)) # Roles if detailed: for role in get_roles_in_node(node): print_role(_get_role(role), detailed=False) else: print (" Roles: {0}".format(", ".join(get_roles_in_node(node)))) # Recipes if detailed: for recipe in get_recipes_in_node(node): print " Recipe:", recipe print " attributes: {0}".format(node.get(recipe, "")) else: print (" Recipes: {0}".format(", ".join(get_recipes_in_node(node)))) # Node attributes print " Node attributes:" for attribute in node.keys(): if attribute == "run_list" or attribute == "name": continue print " {0}: {1}".format(attribute, node[attribute])
def print_header(string): """Prints a colored header""" print(colors.yellow("\n== {0} ==".format(string)))
def print_header(string): """Prints a colored header""" print (colors.yellow("\n== {0} ==".format(string)))