Ejemplo n.º 1
0
 def dumpVars(self):
     super(ZBbuilderInventoryCLI, self).parse()
     if ansible_version.startswith('2.7'):
         from ansible.cli import CLI
         parser = CLI.base_parser(vault_opts=True, inventory_opts=True)
         options, args = parser.parse_args(["-i", "hosts"])
         return self._play_prereqs(options)
     if ansible_version.startswith('2.9'):
         return self._play_prereqs()
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        connection = ['127.0.0.1:11211']

        try:
            super(CacheModule, self).__init__(*args, **kwargs)
            if self.get_option('_uri'):
                connection = self.get_option('_uri')
            self._timeout = self.get_option('_timeout')
            self._prefix = self.get_option('_prefix')
        except KeyError:
            # TODO: remove once we no longer support Ansible 2.9
            if not ansible_base_version.startswith('2.9.'):
                raise AnsibleError(
                    "Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead."
                )
            if C.CACHE_PLUGIN_CONNECTION:
                connection = C.CACHE_PLUGIN_CONNECTION.split(',')
            self._timeout = C.CACHE_PLUGIN_TIMEOUT
            self._prefix = C.CACHE_PLUGIN_PREFIX

        if not HAS_MEMCACHE:
            raise AnsibleError(
                "python-memcached is required for the memcached fact cache")

        self._cache = {}
        self._db = ProxyClientPool(connection, debug=0)
        self._keys = CacheModuleKeys(
            self._db,
            self._db.get(CacheModuleKeys.PREFIX) or [])
Ejemplo n.º 3
0
def test_redis_cachemodule():
    # The _uri option is required for the redis plugin
    connection = '[::1]:6379:1'
    if ansible_version.startswith('2.9.'):
        C.CACHE_PLUGIN_CONNECTION = connection
    assert isinstance(
        cache_loader.get('community.general.redis', **{'_uri': connection}),
        RedisCache)
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        uri = ''

        try:
            super(CacheModule, self).__init__(*args, **kwargs)
            if self.get_option('_uri'):
                uri = self.get_option('_uri')
            self._timeout = float(self.get_option('_timeout'))
            self._prefix = self.get_option('_prefix')
            self._keys_set = self.get_option('_keyset_name')
            self._sentinel_service_name = self.get_option(
                '_sentinel_service_name')
        except KeyError:
            # TODO: remove once we no longer support Ansible 2.9
            if not ansible_base_version.startswith('2.9.'):
                raise AnsibleError(
                    "Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead."
                )
            if C.CACHE_PLUGIN_CONNECTION:
                uri = C.CACHE_PLUGIN_CONNECTION
            self._timeout = float(C.CACHE_PLUGIN_TIMEOUT)
            self._prefix = C.CACHE_PLUGIN_PREFIX
            self._keys_set = 'ansible_cache_keys'

        if not HAS_REDIS:
            raise AnsibleError(
                "The 'redis' python module (version 2.4.5 or newer) is required for the redis fact cache, 'pip install redis'"
            )

        self._cache = {}
        kw = {}

        # tls connection
        tlsprefix = 'tls://'
        if uri.startswith(tlsprefix):
            kw['ssl'] = True
            uri = uri[len(tlsprefix):]

        # redis sentinel connection
        if self._sentinel_service_name:
            self._db = self._get_sentinel_connection(uri, kw)
        # normal connection
        else:
            connection = self._parse_connection(self.re_url_conn, uri)
            self._db = StrictRedis(*connection, **kw)

        display.vv('Redis connection: %s' % self._db)