def to_padded_yaml(data, level=0, indent=2, **kw):
 if (data in [None, '']):
  return ''
 try:
  transformed = yaml.dump(data, indent=indent, allow_unicode=True, default_flow_style=False, Dumper=AnsibleDumper, **kw)
  padded = '\n'.join([(((' ' * level) * indent) + line) for line in transformed.splitlines()])
  return to_text('\n{0}'.format(padded))
 except Exception as my_e:
  raise errors.AnsibleFilterError(('Failed to convert: %s' % my_e))

def to_padded_yaml ( data , level = 0 , indent = 2 , ** kw ) : if ( data in [ None , '' ] ) : return '' try : transformed = yaml . dump ( data , indent = indent , allow_unicode = True , default_flow_style = False , Dumper = AnsibleDumper , ** kw ) padded = '\n' . join ( [ ( ( ( ' ' * level ) * indent ) + line ) for line in transformed . splitlines ( ) ] ) return to_text ( '\n{0}' . format ( padded ) ) except Exception as my_e : raise errors . AnsibleFilterError ( ( 'Failed to convert: %s' % my_e ) )
returns a yaml snippet padded to match the indent level you specify .