本文整理汇总了Python中ansible.parsing.dataloader.DataLoader.load方法的典型用法代码示例。如果您正苦于以下问题:Python DataLoader.load方法的具体用法?Python DataLoader.load怎么用?Python DataLoader.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ansible.parsing.dataloader.DataLoader
的用法示例。
在下文中一共展示了DataLoader.load方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: boilerplate_module
# 需要导入模块: from ansible.parsing.dataloader import DataLoader [as 别名]
# 或者: from ansible.parsing.dataloader.DataLoader import load [as 别名]
def boilerplate_module(modfile, args, interpreter, check, destfile):
""" simulate what ansible does with new style modules """
loader = DataLoader()
complex_args = {}
if args.startswith("@"):
# Argument is a YAML file (JSON is a subset of YAML)
complex_args = utils_vars.combine_vars(complex_args,
loader.load_from_file(args[1:]))
args = ''
elif args.startswith("{"):
# Argument is a YAML document (not a file)
complex_args = utils_vars.combine_vars(complex_args, loader.load(args))
args = ''
if args:
parsed_args = parse_kv(args)
complex_args = utils_vars.combine_vars(complex_args, parsed_args)
task_vars = {}
if interpreter:
if '=' not in interpreter:
print("interpreter must by in the form of \
ansible_python_interpreter=/usr/bin/python")
sys.exit(1)
interpreter_type, interpreter_path = interpreter.split('=')
if not interpreter_type.startswith('ansible_'):
interpreter_type = 'ansible_%s' % interpreter_type
if not interpreter_type.endswith('_interpreter'):
interpreter_type = '%s_interpreter' % interpreter_type
task_vars[interpreter_type] = interpreter_path
if check:
complex_args['_ansible_check_mode'] = True
modname = os.path.basename(modfile)
modname = os.path.splitext(modname)[0]
(module_data, module_style, shebang) = module_common.modify_module(
modname,
modfile,
complex_args,
task_vars=task_vars
)
if module_style == 'new' \
and 'ZIPLOADER_WRAPPER = True' in module_data:
module_style = 'ziploader'
modfile2_path = os.path.expanduser(destfile)
print("* including generated source,\
if any, saving to: %s" % modfile2_path)
if module_style not in ('ziploader', 'old'):
print("* this may offset any line numbers in tracebacks/debuggers!")
modfile2 = open(modfile2_path, 'w')
modfile2.write(module_data)
modfile2.close()
modfile = modfile2_path
return (modfile2_path, modname, module_style)