Determine which provider to use

def verify_provider(self):
        '''
        Determine which provider to use
        '''
        if 'verified_{0}_provider'.format(self.role) in self.opts:
            self.provider = self.opts['verified_{0}_provider'.format(self.role)]
        else:
            desired_provider = self.opts.get('{0}_provider'.format(self.role))
            if not desired_provider:
                if self.verify_pygit2(quiet=True):
                    self.provider = 'pygit2'
                elif self.verify_gitpython(quiet=True):
                    self.provider = 'gitpython'
            else:
                # Ensure non-lowercase providers work
                try:
                    desired_provider = desired_provider.lower()
                except AttributeError:
                    # Should only happen if someone does something silly like
                    # set the provider to a numeric value.
                    desired_provider = six.text_type(desired_provider).lower()
                if desired_provider not in self.git_providers:
                    log.critical(
                        'Invalid %s_provider \'%s\'. Valid choices are: %s',
                        self.role,
                        desired_provider,
                        ', '.join(self.git_providers)
                    )
                    failhard(self.role)
                elif desired_provider == 'pygit2' and self.verify_pygit2():
                    self.provider = 'pygit2'
                elif desired_provider == 'gitpython' and self.verify_gitpython():
                    self.provider = 'gitpython'
        if not hasattr(self, 'provider'):
            log.critical(
                'No suitable %s provider module is installed.', self.role
            )
            failhard(self.role)