'flexibly handle variations in main filenames'

def _resolve_main(self, basepath, main=None):

    post = False
    if (main is None):
        main = 'main'
        post = True
    bare_main = os.path.join(basepath, main)
    possible_mains = (os.path.join(basepath, ('%s.yml' % main)), os.path.join(basepath, ('%s.yaml' % main)), os.path.join(basepath, ('%s.json' % main)))
    if post:
        possible_mains = (possible_mains + (bare_main,))
    else:
        possible_mains = ((bare_main,) + possible_mains)
    if (sum([self._loader.is_file(x) for x in possible_mains]) > 1):
        raise AnsibleError(('found    multiple    main    files    at    %s,    only    one    allowed' % basepath))
    else:
        for m in possible_mains:
            if self._loader.is_file(m):
                return m
        return possible_mains[0]
