The recipe action embeds another YAML recipe. This action offers the
possibility to substitute variables in the recipe that will be embedded.
Usage
Click on the to learn more about the action's options.
Recipe Action
{%set username=username or "user" -%}actions:-action:recipedescription:Recipe that will be embedded# (1)!recipe:recipes/recipe.yaml# (2)!working_dir:upstream# (3)! variables:# (4)! username:{{username}}
[Optional] Recipe description, for documentation purposes
[Required] Relative link to the recipe's YAML file
[Optional] Alternative working directory. This is required to avoid
breaking relative links, when embedding a recipe from another location.
classRecipeAction(Action):""" Recipe action """def__init__(self,args_dict):super().__init__(args_dict)self.args_dict=args_dictself.actions={'conf':ConfAction,'preseed':PreseedAction,'apt':AptAction,'overlay':OverlayAction,'run':RunAction,'extra':ExtraAction,'downloads':DownloadsAction,'recipe':RecipeAction,'debos':DebosAction,}defcreate_action(self,action_type,args):""" Create a new action """try:returnself.actions[action_type](args)exceptKeyErrorasexc:raiseKeyError('Unknown action type!')fromexcdef_load_recipe(self,filename,substitutions=None):""" Load the yaml recipe """recipe_file=self.input_dir/filenamefull_yaml=load_yaml(recipe_file,substitutions)returnfull_yaml['actions']def_working_dir(self,props):""" Define the recipe's working dir """ifworking_dir:=props.get('working_dir'):self.input_dir=pl.Path(working_dir)def_get_args(self,props):""" Get input arguments """ifworking_dir:=props.get('working_dir'):returndict(self.args_dict,input=working_dir)returndict(self.args_dict)defprocess_actions(self,props):""" Perform all actions contained in the recipe """self._working_dir(props)recipe_filename=props['recipe']substitutions=props.get('variables')recipe=self._load_recipe(recipe_filename,substitutions)args_dict=self._get_args(props)foraction_propsinrecipe:action_type=action_props['action']action=self.create_action(action_type,args_dict)action.execute(action_props)self.combine_results(action.result)defperform_debos_action(self,props):self.process_actions(props)defperform_action(self,props):self.process_actions(props)defget_result(self):""" Return results dictionary """returnself.result