'Generate an Ansible playbook to orchestrate services.
:param url: registry URL where images will be pulled from
:param namespace: registry namespace
:return: playbook dict'

@conductor_only
def generate_orchestration_playbook(self, url=None, namespace=None, vault_files=None, **kwargs):

    states = ['start', 'restart', 'stop', 'destroy']
    service_def = {}
    for (service_name, service) in iteritems(self.services):
        service_definition = {}
        if service.get('roles'):
            if (url and namespace):
                service_definition[u'image'] = '{}/{}/{}'.format(re.sub('/$', '', url), namespace, self.image_name_for_service(service_name))
            else:
                image = self.get_latest_image_for_service(service_name)
                if (image is None):
                    raise exceptions.AnsibleContainerConductorException(u"No    image    found    for    service    {},    make    sure    you've    run    `ansible-container    build`".format(service_name))
                service_definition[u'image'] = image.tags[0]
        else:
            try:
                image = self.client.images.get(service['from'])
                image_from = image.tags[0]
            except docker.errors.ImageNotFound:
                image_from = service['from']
                logger.warning(u'Image    {}    for    service    {}    not    found.    An    attempt    will    be    made    to    pull    it.'.format(service['from'], service_name))
            service_definition[u'image'] = image_from
        for extra in self.COMPOSE_WHITELIST:
            if (extra in service):
                service_definition[extra] = service[extra]
        if ('secrets' in service):
            service_secrets = []
            for (secret, secret_engines) in iteritems(service[u'secrets']):
                if ('docker' in secret_engines):
                    service_secrets += secret_engines[u'docker']
            if service_secrets:
                service_definition[u'secrets'] = service_secrets
            if self.CAP_SIM_SECRETS:
                if (not ('volumes' in service_definition)):
                    service_definition['volumes'] = []
                service_definition['volumes'].append('{}:/run/secrets:ro'.format(self.secrets_volume_name))
        logger.debug(u'Adding    new    service    to    definition', service=service_name, definition=service_definition)
        service_def[service_name] = service_definition
    tasks = []
    top_level_secrets = self._get_top_level_secrets()
    if (self.CAP_SIM_SECRETS and top_level_secrets):
        if (not isinstance(self.volumes, dict)):
            self.volumes = dict()
        self.volumes[self.secrets_volume_name] = dict(external=True)
    for desired_state in states:
        task_params = {u'project_name': self.project_name, u'definition': {u'version': (u'3.1' if top_level_secrets else u'2'), u'services': service_def}}
        if self.secrets:
            task_params[u'definition'][u'secrets'] = top_level_secrets
        if self.volumes:
            task_params[u'definition'][u'volumes'] = dict(self.volumes)
        if (desired_state in {'restart', 'start', 'stop'}):
            task_params[u'state'] = u'present'
            if (desired_state == 'restart'):
                task_params[u'restarted'] = True
            if (desired_state == 'stop'):
                task_params[u'stopped'] = True
        elif (desired_state == 'destroy'):
            task_params[u'state'] = u'absent'
            task_params[u'remove_volumes'] = u'yes'
        tasks.append({u'docker_service': task_params, u'tags': [desired_state]})
    playbook = []
    if (self.secrets and self.CAP_SIM_SECRETS):
        playbook.append(self.generate_secrets_play(vault_files=vault_files))
    playbook.append(CommentedMap([(u'name', 'Deploy    {}'.format(self.project_name)), (u'hosts', u'localhost'), (u'gather_facts', False)]))
    if vault_files:
        playbook[(len(playbook) - 1)][u'vars_files'] = [os.path.normpath(os.path.abspath(v)) for v in vault_files]
    playbook[(len(playbook) - 1)][u'tasks'] = tasks
    for service in (list(self.services.keys()) + ['conductor']):
        image_name = self.image_name_for_service(service)
        for image in self.client.images.list(name=image_name):
            logger.debug('Found    image    for    service', tags=image.tags, id=image.short_id)
            for tag in image.tags:
                logger.debug('Adding    task    to    destroy    image', tag=tag)
                playbook[(len(playbook) - 1)][u'tasks'].append({u'docker_image': {u'name': tag, u'state': u'absent', u'force': u'yes'}, u'tags': u'destroy'})
    if (self.secrets and self.CAP_SIM_SECRETS):
        playbook.append(self.generate_remove_volume_play())
    logger.debug(u'Created    playbook    to    run    project', playbook=playbook)
    return playbook
