'Returns a dictionary of so-called "magic" variables in Ansible,
which are special variables we set internally for use.'

def _get_magic_variables(self, play, host, task, include_hostvars, include_delegate_to):

    variables = {}
    variables['playbook_dir'] = os.path.abspath(self._loader.get_basedir())
    variables['ansible_playbook_python'] = sys.executable
    if host:
        if self._inventory:
            variables['groups'] = self._inventory.get_groups_dict()
    if play:
        variables['role_names'] = [r._role_name for r in play.roles]
    if task:
        if task._role:
            variables['role_name'] = task._role.get_name()
            variables['role_path'] = task._role._role_path
            variables['role_uuid'] = text_type(task._role._uuid)
    if (self._inventory is not None):
        if play:
            templar = Templar(loader=self._loader)
            if templar.is_template(play.hosts):
                pattern = 'all'
            else:
                pattern = (play.hosts or 'all')
            variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=pattern, ignore_restrictions=True)]
            variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if (x not in play._removed_hosts)]
            variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts() if (x.name not in play._removed_hosts)]
            variables['play_hosts'] = variables['ansible_play_batch']
    variables['omit'] = self._omit_token
    for (option, option_value) in iteritems(self._options_vars):
        variables[option] = option_value
    if ((self._hostvars is not None) and include_hostvars):
        variables['hostvars'] = self._hostvars
    return variables
