plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9379)
* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting. * Improve formulation. Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> * Use more f-strings. * Remove unicode prefix for strings. --------- Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>pull/9447/head
parent
4b4e4b7e0a
commit
2203560867
|
@ -0,0 +1,26 @@
|
||||||
|
minor_changes:
|
||||||
|
- "shutdown action plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "redis cache plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "logentries callback plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "slack callback plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "chroot connection plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "from_csv filter plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "from_ini filter plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "to_ini filter plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "cobbler inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "gitlab_runners inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "iocage inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "lxd inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "nmap inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "opennebula inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "proxmox inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "scaleway inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "virtualbox inventory plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "cyberarkpassword lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "dig lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "dnstxt lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "etcd3 lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "lmdb_kv lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "manifold lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "onepassword lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
||||||
|
- "tss lookup plugin - clean up string conversions (https://github.com/ansible-collections/community.general/pull/9379)."
|
|
@ -177,7 +177,7 @@ class ActionModule(ActionBase):
|
||||||
except AnsibleConnectionFailure as e:
|
except AnsibleConnectionFailure as e:
|
||||||
# If the connection is closed too quickly due to the system being shutdown, carry on
|
# If the connection is closed too quickly due to the system being shutdown, carry on
|
||||||
display.debug(
|
display.debug(
|
||||||
f'{self._task.action}: AnsibleConnectionFailure caught and handled: {to_text(e)}')
|
f'{self._task.action}: AnsibleConnectionFailure caught and handled: {e}')
|
||||||
shutdown_result['rc'] = 0
|
shutdown_result['rc'] = 0
|
||||||
|
|
||||||
if shutdown_result['rc'] != 0:
|
if shutdown_result['rc'] != 0:
|
||||||
|
|
|
@ -73,7 +73,6 @@ import time
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder
|
from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder
|
||||||
from ansible.plugins.cache import BaseCacheModule
|
from ansible.plugins.cache import BaseCacheModule
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -169,7 +168,7 @@ class CacheModule(BaseCacheModule):
|
||||||
try:
|
try:
|
||||||
return scon.master_for(self._sentinel_service_name, socket_timeout=0.2)
|
return scon.master_for(self._sentinel_service_name, socket_timeout=0.2)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise AnsibleError(f'Could not connect to redis sentinel: {to_native(exc)}')
|
raise AnsibleError(f'Could not connect to redis sentinel: {exc}')
|
||||||
|
|
||||||
def _make_key(self, key):
|
def _make_key(self, key):
|
||||||
return self._prefix + key
|
return self._prefix + key
|
||||||
|
|
|
@ -92,16 +92,16 @@ class CallbackModule(CallbackBase):
|
||||||
stat = stats.summarize(host)
|
stat = stats.summarize(host)
|
||||||
|
|
||||||
self._display.display(
|
self._display.display(
|
||||||
f"{hostcolor(host, stat)} : {colorize(u'ok', stat['ok'], C.COLOR_OK)} {colorize(u'changed', stat['changed'], C.COLOR_CHANGED)} "
|
f"{hostcolor(host, stat)} : {colorize('ok', stat['ok'], C.COLOR_OK)} {colorize('changed', stat['changed'], C.COLOR_CHANGED)} "
|
||||||
f"{colorize(u'unreachable', stat['unreachable'], C.COLOR_UNREACHABLE)} {colorize(u'failed', stat['failures'], C.COLOR_ERROR)} "
|
f"{colorize('unreachable', stat['unreachable'], C.COLOR_UNREACHABLE)} {colorize('failed', stat['failures'], C.COLOR_ERROR)} "
|
||||||
f"{colorize(u'rescued', stat['rescued'], C.COLOR_OK)} {colorize(u'ignored', stat['ignored'], C.COLOR_WARN)}",
|
f"{colorize('rescued', stat['rescued'], C.COLOR_OK)} {colorize('ignored', stat['ignored'], C.COLOR_WARN)}",
|
||||||
screen_only=True
|
screen_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
self._display.display(
|
self._display.display(
|
||||||
f"{hostcolor(host, stat, False)} : {colorize(u'ok', stat['ok'], None)} {colorize(u'changed', stat['changed'], None)} "
|
f"{hostcolor(host, stat, False)} : {colorize('ok', stat['ok'], None)} {colorize('changed', stat['changed'], None)} "
|
||||||
f"{colorize(u'unreachable', stat['unreachable'], None)} {colorize(u'failed', stat['failures'], None)} "
|
f"{colorize('unreachable', stat['unreachable'], None)} {colorize('failed', stat['failures'], None)} "
|
||||||
f"{colorize(u'rescued', stat['rescued'], None)} {colorize(u'ignored', stat['ignored'], None)}",
|
f"{colorize('rescued', stat['rescued'], None)} {colorize('ignored', stat['ignored'], None)}",
|
||||||
log_only=True
|
log_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -483,9 +483,9 @@ class CallbackModule(CallbackModule_default):
|
||||||
for h in hosts:
|
for h in hosts:
|
||||||
t = stats.summarize(h)
|
t = stats.summarize(h)
|
||||||
self._display.display(
|
self._display.display(
|
||||||
f"{hostcolor(h, t)} : {colorize(u'ok', t['ok'], C.COLOR_OK)} {colorize(u'changed', t['changed'], C.COLOR_CHANGED)} "
|
f"{hostcolor(h, t)} : {colorize('ok', t['ok'], C.COLOR_OK)} {colorize('changed', t['changed'], C.COLOR_CHANGED)} "
|
||||||
f"{colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE)} {colorize(u'failed', t['failures'], C.COLOR_ERROR)} "
|
f"{colorize('unreachable', t['unreachable'], C.COLOR_UNREACHABLE)} {colorize('failed', t['failures'], C.COLOR_ERROR)} "
|
||||||
f"{colorize(u'rescued', t['rescued'], C.COLOR_OK)} {colorize(u'ignored', t['ignored'], C.COLOR_WARN)}",
|
f"{colorize('rescued', t['rescued'], C.COLOR_OK)} {colorize('ignored', t['ignored'], C.COLOR_WARN)}",
|
||||||
screen_only=True
|
screen_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ class PlainTextSocketAppender(object):
|
||||||
# Error message displayed when an incorrect Token has been detected
|
# Error message displayed when an incorrect Token has been detected
|
||||||
self.INVALID_TOKEN = "\n\nIt appears the LOGENTRIES_TOKEN parameter you entered is incorrect!\n\n"
|
self.INVALID_TOKEN = "\n\nIt appears the LOGENTRIES_TOKEN parameter you entered is incorrect!\n\n"
|
||||||
# Unicode Line separator character \u2028
|
# Unicode Line separator character \u2028
|
||||||
self.LINE_SEP = u'\u2028'
|
self.LINE_SEP = '\u2028'
|
||||||
|
|
||||||
self._display = display
|
self._display = display
|
||||||
self._conn = None
|
self._conn = None
|
||||||
|
@ -153,7 +153,7 @@ class PlainTextSocketAppender(object):
|
||||||
self.open_connection()
|
self.open_connection()
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._display.vvvv(f"Unable to connect to Logentries: {to_text(e)}")
|
self._display.vvvv(f"Unable to connect to Logentries: {e}")
|
||||||
|
|
||||||
root_delay *= 2
|
root_delay *= 2
|
||||||
if root_delay > self.MAX_DELAY:
|
if root_delay > self.MAX_DELAY:
|
||||||
|
@ -175,8 +175,8 @@ class PlainTextSocketAppender(object):
|
||||||
# Replace newlines with Unicode line separator
|
# Replace newlines with Unicode line separator
|
||||||
# for multi-line events
|
# for multi-line events
|
||||||
data = to_text(data, errors='surrogate_or_strict')
|
data = to_text(data, errors='surrogate_or_strict')
|
||||||
multiline = data.replace(u'\n', self.LINE_SEP)
|
multiline = data.replace('\n', self.LINE_SEP)
|
||||||
multiline += u"\n"
|
multiline += "\n"
|
||||||
# Send data, reconnect if needed
|
# Send data, reconnect if needed
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -249,7 +249,7 @@ class CallbackModule(CallbackBase):
|
||||||
self.use_tls = self.get_option('use_tls')
|
self.use_tls = self.get_option('use_tls')
|
||||||
self.flatten = self.get_option('flatten')
|
self.flatten = self.get_option('flatten')
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self._display.warning(f"Missing option for Logentries callback plugin: {to_text(e)}")
|
self._display.warning(f"Missing option for Logentries callback plugin: {e}")
|
||||||
self.disabled = True
|
self.disabled = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -62,7 +62,6 @@ import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from ansible import context
|
from ansible import context
|
||||||
from ansible.module_utils.common.text.converters import to_text
|
|
||||||
from ansible.module_utils.urls import open_url
|
from ansible.module_utils.urls import open_url
|
||||||
from ansible.plugins.callback import CallbackBase
|
from ansible.plugins.callback import CallbackBase
|
||||||
|
|
||||||
|
@ -138,7 +137,7 @@ class CallbackModule(CallbackBase):
|
||||||
headers=headers)
|
headers=headers)
|
||||||
return response.read()
|
return response.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._display.warning(f'Could not submit message to Slack: {to_text(e)}')
|
self._display.warning(f'Could not submit message to Slack: {e}')
|
||||||
|
|
||||||
def v2_playbook_on_start(self, playbook):
|
def v2_playbook_on_start(self, playbook):
|
||||||
self.playbook_name = os.path.basename(playbook._file_name)
|
self.playbook_name = os.path.basename(playbook._file_name)
|
||||||
|
|
|
@ -110,12 +110,12 @@ class CallbackModule(CallbackModule_default):
|
||||||
if name and play.hosts:
|
if name and play.hosts:
|
||||||
msg = f"\n- {name} (in check mode) on hosts: {','.join(play.hosts)} -"
|
msg = f"\n- {name} (in check mode) on hosts: {','.join(play.hosts)} -"
|
||||||
else:
|
else:
|
||||||
msg = u"- check mode -"
|
msg = "- check mode -"
|
||||||
else:
|
else:
|
||||||
if name and play.hosts:
|
if name and play.hosts:
|
||||||
msg = f"\n- {name} on hosts: {','.join(play.hosts)} -"
|
msg = f"\n- {name} on hosts: {','.join(play.hosts)} -"
|
||||||
else:
|
else:
|
||||||
msg = u"---"
|
msg = "---"
|
||||||
|
|
||||||
self._display.display(msg)
|
self._display.display(msg)
|
||||||
|
|
||||||
|
@ -196,16 +196,16 @@ class CallbackModule(CallbackModule_default):
|
||||||
t = stats.summarize(h)
|
t = stats.summarize(h)
|
||||||
|
|
||||||
self._display.display(
|
self._display.display(
|
||||||
f" {hostcolor(h, t)} : {colorize(u'ok', t['ok'], C.COLOR_OK)} {colorize(u'changed', t['changed'], C.COLOR_CHANGED)} "
|
f" {hostcolor(h, t)} : {colorize('ok', t['ok'], C.COLOR_OK)} {colorize('changed', t['changed'], C.COLOR_CHANGED)} "
|
||||||
f"{colorize(u'unreachable', t['unreachable'], C.COLOR_UNREACHABLE)} {colorize(u'failed', t['failures'], C.COLOR_ERROR)} "
|
f"{colorize('unreachable', t['unreachable'], C.COLOR_UNREACHABLE)} {colorize('failed', t['failures'], C.COLOR_ERROR)} "
|
||||||
f"{colorize(u'rescued', t['rescued'], C.COLOR_OK)} {colorize(u'ignored', t['ignored'], C.COLOR_WARN)}",
|
f"{colorize('rescued', t['rescued'], C.COLOR_OK)} {colorize('ignored', t['ignored'], C.COLOR_WARN)}",
|
||||||
screen_only=True
|
screen_only=True
|
||||||
)
|
)
|
||||||
|
|
||||||
self._display.display(
|
self._display.display(
|
||||||
f" {hostcolor(h, t, False)} : {colorize(u'ok', t['ok'], None)} {colorize(u'changed', t['changed'], None)} "
|
f" {hostcolor(h, t, False)} : {colorize('ok', t['ok'], None)} {colorize('changed', t['changed'], None)} "
|
||||||
f"{colorize(u'unreachable', t['unreachable'], None)} {colorize(u'failed', t['failures'], None)} {colorize(u'rescued', t['rescued'], None)} "
|
f"{colorize('unreachable', t['unreachable'], None)} {colorize('failed', t['failures'], None)} {colorize('rescued', t['rescued'], None)} "
|
||||||
f"{colorize(u'ignored', t['ignored'], None)}",
|
f"{colorize('ignored', t['ignored'], None)}",
|
||||||
log_only=True
|
log_only=True
|
||||||
)
|
)
|
||||||
if stats.custom and self.get_option('show_custom_stats'):
|
if stats.custom and self.get_option('show_custom_stats'):
|
||||||
|
|
|
@ -45,7 +45,7 @@ from ansible.plugins.callback.default import CallbackModule as Default
|
||||||
# from http://stackoverflow.com/a/15423007/115478
|
# from http://stackoverflow.com/a/15423007/115478
|
||||||
def should_use_block(value):
|
def should_use_block(value):
|
||||||
"""Returns true if string should be in block format"""
|
"""Returns true if string should be in block format"""
|
||||||
for c in u"\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029":
|
for c in "\u000a\u000d\u001c\u001d\u001e\u0085\u2028\u2029":
|
||||||
if c in value:
|
if c in value:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -94,7 +94,7 @@ from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.basic import is_executable
|
from ansible.module_utils.basic import is_executable
|
||||||
from ansible.module_utils.common.process import get_bin_path
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.six.moves import shlex_quote
|
from ansible.module_utils.six.moves import shlex_quote
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
from ansible.module_utils.common.text.converters import to_bytes
|
||||||
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
from ansible.plugins.connection import ConnectionBase, BUFSIZE
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ class Connection(ConnectionBase):
|
||||||
try:
|
try:
|
||||||
self.chroot_cmd = get_bin_path(self.get_option('chroot_exe'))
|
self.chroot_cmd = get_bin_path(self.get_option('chroot_exe'))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise AnsibleError(to_native(e))
|
raise AnsibleError(str(e))
|
||||||
|
|
||||||
super(Connection, self)._connect()
|
super(Connection, self)._connect()
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Connection(ConnectionBase):
|
||||||
super(Connection, self)._connect()
|
super(Connection, self)._connect()
|
||||||
|
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
self._display.vvv(u"ESTABLISH Incus CONNECTION FOR USER: root",
|
self._display.vvv("ESTABLISH Incus CONNECTION FOR USER: root",
|
||||||
host=self._instance())
|
host=self._instance())
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ class Connection(ConnectionBase):
|
||||||
super(Connection, self)._connect()
|
super(Connection, self)._connect()
|
||||||
|
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
self._display.vvv(u"ESTABLISH LXD CONNECTION FOR USER: root", host=self._host())
|
self._display.vvv("ESTABLISH LXD CONNECTION FOR USER: root", host=self._host())
|
||||||
self._connected = True
|
self._connected = True
|
||||||
|
|
||||||
def exec_command(self, cmd, in_data=None, sudoable=True):
|
def exec_command(self, cmd, in_data=None, sudoable=True):
|
||||||
|
|
|
@ -81,7 +81,6 @@ RETURN = '''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.errors import AnsibleFilterError
|
from ansible.errors import AnsibleFilterError
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.module_utils.csv import (initialize_dialect, read_csv, CSVError,
|
from ansible_collections.community.general.plugins.module_utils.csv import (initialize_dialect, read_csv, CSVError,
|
||||||
DialectNotAvailableError,
|
DialectNotAvailableError,
|
||||||
|
@ -99,7 +98,7 @@ def from_csv(data, dialect='excel', fieldnames=None, delimiter=None, skipinitial
|
||||||
try:
|
try:
|
||||||
dialect = initialize_dialect(dialect, **dialect_params)
|
dialect = initialize_dialect(dialect, **dialect_params)
|
||||||
except (CustomDialectFailureError, DialectNotAvailableError) as e:
|
except (CustomDialectFailureError, DialectNotAvailableError) as e:
|
||||||
raise AnsibleFilterError(to_native(e))
|
raise AnsibleFilterError(str(e))
|
||||||
|
|
||||||
reader = read_csv(data, dialect, fieldnames)
|
reader = read_csv(data, dialect, fieldnames)
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ def from_csv(data, dialect='excel', fieldnames=None, delimiter=None, skipinitial
|
||||||
for row in reader:
|
for row in reader:
|
||||||
data_list.append(row)
|
data_list.append(row)
|
||||||
except CSVError as e:
|
except CSVError as e:
|
||||||
raise AnsibleFilterError("Unable to process file: %s" % to_native(e))
|
raise AnsibleFilterError(f"Unable to process file: {e}")
|
||||||
|
|
||||||
return data_list
|
return data_list
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,6 @@ from ansible.errors import AnsibleFilterError
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
|
|
||||||
|
|
||||||
class IniParser(ConfigParser):
|
class IniParser(ConfigParser):
|
||||||
|
@ -83,8 +82,7 @@ def from_ini(obj):
|
||||||
try:
|
try:
|
||||||
parser.read_file(StringIO(obj))
|
parser.read_file(StringIO(obj))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise AnsibleFilterError(f'from_ini failed to parse given string: '
|
raise AnsibleFilterError(f'from_ini failed to parse given string: {ex}', orig_exc=ex)
|
||||||
f'{to_native(ex)}', orig_exc=ex)
|
|
||||||
|
|
||||||
return parser.as_dict()
|
return parser.as_dict()
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,6 @@ from ansible.errors import AnsibleFilterError
|
||||||
from ansible.module_utils.common._collections_compat import Mapping
|
from ansible.module_utils.common._collections_compat import Mapping
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
from ansible.module_utils.six.moves.configparser import ConfigParser
|
from ansible.module_utils.six.moves.configparser import ConfigParser
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
|
|
||||||
|
|
||||||
class IniParser(ConfigParser):
|
class IniParser(ConfigParser):
|
||||||
|
@ -79,7 +78,7 @@ def to_ini(obj):
|
||||||
ini_parser.read_dict(obj)
|
ini_parser.read_dict(obj)
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise AnsibleFilterError('to_ini failed to parse given dict:'
|
raise AnsibleFilterError('to_ini failed to parse given dict:'
|
||||||
f'{to_native(ex)}', orig_exc=ex)
|
f'{ex}', orig_exc=ex)
|
||||||
|
|
||||||
# catching empty dicts
|
# catching empty dicts
|
||||||
if obj == dict():
|
if obj == dict():
|
||||||
|
|
|
@ -118,7 +118,6 @@ password: secure
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.common.text.converters import to_text
|
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, to_safe_group_name
|
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable, to_safe_group_name
|
||||||
from ansible.module_utils.six import text_type
|
from ansible.module_utils.six import text_type
|
||||||
|
|
||||||
|
@ -377,7 +376,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
try:
|
try:
|
||||||
self.inventory.set_variable(hostname, 'cobbler', make_unsafe(host))
|
self.inventory.set_variable(hostname, 'cobbler', make_unsafe(host))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self.display.warning(f"Could not set host info for {hostname}: {to_text(e)}")
|
self.display.warning(f"Could not set host info for {hostname}: {e}")
|
||||||
|
|
||||||
if self.get_option('want_ip_addresses'):
|
if self.get_option('want_ip_addresses'):
|
||||||
self.inventory.set_variable(self.group, 'cobbler_ipv4_addresses', make_unsafe(ip_addresses))
|
self.inventory.set_variable(self.group, 'cobbler_ipv4_addresses', make_unsafe(ip_addresses))
|
||||||
|
|
|
@ -81,7 +81,6 @@ keyed_groups:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleParserError
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||||
|
@ -124,7 +123,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
# Create groups based on variable values and add the corresponding hosts to it
|
# Create groups based on variable values and add the corresponding hosts to it
|
||||||
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), host_attrs, host, strict=strict)
|
self._add_host_to_keyed_groups(self.get_option('keyed_groups'), host_attrs, host, strict=strict)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleParserError(f'Unable to fetch hosts from GitLab API, this was the original exception: {to_native(e)}')
|
raise AnsibleParserError(f'Unable to fetch hosts from GitLab API, this was the original exception: {e}')
|
||||||
|
|
||||||
def verify_file(self, path):
|
def verify_file(self, path):
|
||||||
"""Return the possibly of a file being consumable by this plugin."""
|
"""Return the possibly of a file being consumable by this plugin."""
|
||||||
|
|
|
@ -195,17 +195,15 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
p = Popen(cmd_list, stdout=PIPE, stderr=PIPE, env=my_env)
|
p = Popen(cmd_list, stdout=PIPE, stderr=PIPE, env=my_env)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise AnsibleError('Failed to run cmd=%s, rc=%s, stderr=%s' %
|
raise AnsibleError(f'Failed to run cmd={cmd_list}, rc={p.returncode}, stderr={to_native(stderr)}')
|
||||||
(cmd_list, p.returncode, to_native(stderr)))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||||
except UnicodeError as e:
|
except UnicodeError as e:
|
||||||
raise AnsibleError('Invalid (non unicode) input returned: %s' % to_native(e)) from e
|
raise AnsibleError(f'Invalid (non unicode) input returned: {e}') from e
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleParserError('Failed to parse %s: %s' %
|
raise AnsibleParserError(f'Failed to parse {to_native(path)}: {e}') from e
|
||||||
(to_native(path), to_native(e))) from e
|
|
||||||
|
|
||||||
results = {'_meta': {'hostvars': {}}}
|
results = {'_meta': {'hostvars': {}}}
|
||||||
self.get_jails(t_stdout, results)
|
self.get_jails(t_stdout, results)
|
||||||
|
@ -220,16 +218,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
p = Popen(cmd_get_properties, stdout=PIPE, stderr=PIPE, env=my_env)
|
p = Popen(cmd_get_properties, stdout=PIPE, stderr=PIPE, env=my_env)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
raise AnsibleError('Failed to run cmd=%s, rc=%s, stderr=%s' %
|
raise AnsibleError(
|
||||||
(cmd_get_properties, p.returncode, to_native(stderr)))
|
f'Failed to run cmd={cmd_get_properties}, rc={p.returncode}, stderr={to_native(stderr)}')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||||
except UnicodeError as e:
|
except UnicodeError as e:
|
||||||
raise AnsibleError('Invalid (non unicode) input returned: %s' % to_native(e)) from e
|
raise AnsibleError(f'Invalid (non unicode) input returned: {e}') from e
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError('Failed to get properties: %s' % to_native(e)) from e
|
raise AnsibleError(f'Failed to get properties: {e}') from e
|
||||||
|
|
||||||
self.get_properties(t_stdout, results, hostname)
|
self.get_properties(t_stdout, results, hostname)
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
with open(path, 'r') as json_file:
|
with open(path, 'r') as json_file:
|
||||||
return json.load(json_file)
|
return json.load(json_file)
|
||||||
except (IOError, json.decoder.JSONDecodeError) as err:
|
except (IOError, json.decoder.JSONDecodeError) as err:
|
||||||
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {to_native(err)}')
|
raise AnsibleParserError(f'Could not load the test data from {to_native(path)}: {err}')
|
||||||
|
|
||||||
def save_json_data(self, path, file_name=None):
|
def save_json_data(self, path, file_name=None):
|
||||||
"""save data as json
|
"""save data as json
|
||||||
|
@ -241,7 +241,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
with open(os.path.abspath(os.path.join(cwd, *path)), 'w') as json_file:
|
with open(os.path.abspath(os.path.join(cwd, *path)), 'w') as json_file:
|
||||||
json.dump(self.data, json_file)
|
json.dump(self.data, json_file)
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
raise AnsibleParserError(f'Could not save data: {to_native(err)}')
|
raise AnsibleParserError(f'Could not save data: {err}')
|
||||||
|
|
||||||
def verify_file(self, path):
|
def verify_file(self, path):
|
||||||
"""Check the config
|
"""Check the config
|
||||||
|
@ -281,7 +281,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
if not isinstance(url, str):
|
if not isinstance(url, str):
|
||||||
return False
|
return False
|
||||||
if not url.startswith(('unix:', 'https:')):
|
if not url.startswith(('unix:', 'https:')):
|
||||||
raise AnsibleError(f'URL is malformed: {to_native(url)}')
|
raise AnsibleError(f'URL is malformed: {url}')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _connect_to_socket(self):
|
def _connect_to_socket(self):
|
||||||
|
@ -306,7 +306,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
return socket_connection
|
return socket_connection
|
||||||
except LXDClientException as err:
|
except LXDClientException as err:
|
||||||
error_storage[url] = err
|
error_storage[url] = err
|
||||||
raise AnsibleError(f'No connection to the socket: {to_native(error_storage)}')
|
raise AnsibleError(f'No connection to the socket: {error_storage}')
|
||||||
|
|
||||||
def _get_networks(self):
|
def _get_networks(self):
|
||||||
"""Get Networknames
|
"""Get Networknames
|
||||||
|
@ -579,7 +579,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
else:
|
else:
|
||||||
path[instance_name][key] = value
|
path[instance_name][key] = value
|
||||||
except KeyError as err:
|
except KeyError as err:
|
||||||
raise AnsibleParserError(f"Unable to store Information: {to_native(err)}")
|
raise AnsibleParserError(f"Unable to store Information: {err}")
|
||||||
|
|
||||||
def extract_information_from_instance_configs(self):
|
def extract_information_from_instance_configs(self):
|
||||||
"""Process configuration information
|
"""Process configuration information
|
||||||
|
@ -792,7 +792,7 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
network = ipaddress.ip_network(to_text(self.groupby[group_name].get('attribute')))
|
network = ipaddress.ip_network(to_text(self.groupby[group_name].get('attribute')))
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
raise AnsibleParserError(
|
raise AnsibleParserError(
|
||||||
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {to_native(err)}")
|
f"Error while parsing network range {self.groupby[group_name].get('attribute')}: {err}")
|
||||||
|
|
||||||
for instance_name in self.inventory.hosts:
|
for instance_name in self.inventory.hosts:
|
||||||
if self.data['inventory'][instance_name].get('network_interfaces') is not None:
|
if self.data['inventory'][instance_name].get('network_interfaces') is not None:
|
||||||
|
@ -1120,6 +1120,6 @@ class InventoryModule(BaseInventoryPlugin):
|
||||||
self.url = self.get_option('url')
|
self.url = self.get_option('url')
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise AnsibleParserError(
|
raise AnsibleParserError(
|
||||||
f'All correct options required: {to_native(err)}')
|
f'All correct options required: {err}')
|
||||||
# Call our internal helper to populate the dynamic inventory
|
# Call our internal helper to populate the dynamic inventory
|
||||||
self._populate()
|
self._populate()
|
||||||
|
|
|
@ -178,7 +178,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
try:
|
try:
|
||||||
self._nmap = get_bin_path('nmap')
|
self._nmap = get_bin_path('nmap')
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise AnsibleParserError(f'nmap inventory plugin requires the nmap cli tool to work: {to_native(e)}')
|
raise AnsibleParserError(f'nmap inventory plugin requires the nmap cli tool to work: {e}')
|
||||||
|
|
||||||
super(InventoryModule, self).parse(inventory, loader, path, cache=cache)
|
super(InventoryModule, self).parse(inventory, loader, path, cache=cache)
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
try:
|
try:
|
||||||
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||||
except UnicodeError as e:
|
except UnicodeError as e:
|
||||||
raise AnsibleParserError(f'Invalid (non unicode) input returned: {to_native(e)}')
|
raise AnsibleParserError(f'Invalid (non unicode) input returned: {e}')
|
||||||
|
|
||||||
for line in t_stdout.splitlines():
|
for line in t_stdout.splitlines():
|
||||||
hits = self.find_host.match(line)
|
hits = self.find_host.match(line)
|
||||||
|
@ -300,7 +300,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
results[-1]['ports'] = ports
|
results[-1]['ports'] = ports
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleParserError(f"failed to parse {to_native(path)}: {to_native(e)} ")
|
raise AnsibleParserError(f"failed to parse {to_native(path)}: {e} ")
|
||||||
|
|
||||||
if cache_needs_update:
|
if cache_needs_update:
|
||||||
self._cache[cache_key] = results
|
self._cache[cache_key] = results
|
||||||
|
|
|
@ -96,7 +96,6 @@ except ImportError:
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
|
|
||||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||||
|
|
||||||
|
@ -172,7 +171,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
try:
|
try:
|
||||||
vm_pool = one_client.vmpool.infoextended(-2, -1, -1, 3)
|
vm_pool = one_client.vmpool.infoextended(-2, -1, -1, 3)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"Something happened during XML-RPC call: {to_native(e)}")
|
raise AnsibleError(f"Something happened during XML-RPC call: {e}")
|
||||||
|
|
||||||
return vm_pool
|
return vm_pool
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,6 @@ from ansible.module_utils.common._collections_compat import MutableMapping
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
from ansible.module_utils.six import string_types
|
from ansible.module_utils.six import string_types
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -523,7 +522,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
if not self._compose(host_filter, properties):
|
if not self._compose(host_filter, properties):
|
||||||
return False
|
return False
|
||||||
except Exception as e: # pylint: disable=broad-except
|
except Exception as e: # pylint: disable=broad-except
|
||||||
message = f"Could not evaluate host filter {host_filter} for host {name} - {to_native(e)}"
|
message = f"Could not evaluate host filter {host_filter} for host {name} - {e}"
|
||||||
if self.strict:
|
if self.strict:
|
||||||
raise AnsibleError(message)
|
raise AnsibleError(message)
|
||||||
display.warning(message)
|
display.warning(message)
|
||||||
|
|
|
@ -125,7 +125,7 @@ from ansible.plugins.inventory import BaseInventoryPlugin, Constructable
|
||||||
from ansible_collections.community.general.plugins.module_utils.scaleway import SCALEWAY_LOCATION, parse_pagination_link
|
from ansible_collections.community.general.plugins.module_utils.scaleway import SCALEWAY_LOCATION, parse_pagination_link
|
||||||
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
from ansible_collections.community.general.plugins.plugin_utils.unsafe import make_unsafe
|
||||||
from ansible.module_utils.urls import open_url
|
from ansible.module_utils.urls import open_url
|
||||||
from ansible.module_utils.common.text.converters import to_native, to_text
|
from ansible.module_utils.common.text.converters import to_text
|
||||||
from ansible.module_utils.six import raise_from
|
from ansible.module_utils.six import raise_from
|
||||||
|
|
||||||
import ansible.module_utils.six.moves.urllib.parse as urllib_parse
|
import ansible.module_utils.six.moves.urllib.parse as urllib_parse
|
||||||
|
@ -140,7 +140,7 @@ def _fetch_information(token, url):
|
||||||
headers={'X-Auth-Token': token,
|
headers={'X-Auth-Token': token,
|
||||||
'Content-type': 'application/json'})
|
'Content-type': 'application/json'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"Error while fetching {url}: {to_native(e)}")
|
raise AnsibleError(f"Error while fetching {url}: {e}")
|
||||||
try:
|
try:
|
||||||
raw_json = json.loads(to_text(response.read()))
|
raw_json = json.loads(to_text(response.read()))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
|
@ -76,7 +76,7 @@ import os
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
from ansible.errors import AnsibleParserError
|
from ansible.errors import AnsibleParserError
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_native, to_text
|
from ansible.module_utils.common.text.converters import to_bytes, to_text
|
||||||
from ansible.module_utils.common._collections_compat import MutableMapping
|
from ansible.module_utils.common._collections_compat import MutableMapping
|
||||||
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable
|
||||||
from ansible.module_utils.common.process import get_bin_path
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
|
@ -352,7 +352,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
try:
|
try:
|
||||||
p = Popen(cmd, stdout=PIPE)
|
p = Popen(cmd, stdout=PIPE)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleParserError(to_native(e))
|
raise AnsibleParserError(str(e))
|
||||||
|
|
||||||
source_data = p.stdout.read().splitlines()
|
source_data = p.stdout.read().splitlines()
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ from subprocess import Popen
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
from ansible.module_utils.common.text.converters import to_bytes, to_text, to_native
|
from ansible.module_utils.common.text.converters import to_bytes, to_native
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
|
||||||
display = Display()
|
display = Display()
|
||||||
|
@ -164,7 +164,7 @@ class CyberarkPassword:
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise AnsibleError(e.output)
|
raise AnsibleError(e.output)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise AnsibleError(f"ERROR - AIM not installed or clipasswordsdk not in standard location. ERROR=({to_text(e.errno)}) => {e.strerror} ")
|
raise AnsibleError(f"ERROR - AIM not installed or clipasswordsdk not in standard location. ERROR=({e.errno}) => {e.strerror} ")
|
||||||
|
|
||||||
return [result_dict]
|
return [result_dict]
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,6 @@ RETURN = """
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
from ansible.module_utils.parsing.convert_bool import boolean
|
from ansible.module_utils.parsing.convert_bool import boolean
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
import socket
|
import socket
|
||||||
|
@ -345,7 +344,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
rdclass = dns.rdataclass.from_text(self.get_option('class'))
|
rdclass = dns.rdataclass.from_text(self.get_option('class'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"dns lookup illegal CLASS: {to_native(e)}")
|
raise AnsibleError(f"dns lookup illegal CLASS: {e}")
|
||||||
myres.retry_servfail = self.get_option('retry_servfail')
|
myres.retry_servfail = self.get_option('retry_servfail')
|
||||||
|
|
||||||
for t in terms:
|
for t in terms:
|
||||||
|
@ -363,7 +362,7 @@ class LookupModule(LookupBase):
|
||||||
nsaddr = dns.resolver.query(ns)[0].address
|
nsaddr = dns.resolver.query(ns)[0].address
|
||||||
nameservers.append(nsaddr)
|
nameservers.append(nsaddr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"dns lookup NS: {to_native(e)}")
|
raise AnsibleError(f"dns lookup NS: {e}")
|
||||||
continue
|
continue
|
||||||
if '=' in t:
|
if '=' in t:
|
||||||
try:
|
try:
|
||||||
|
@ -379,7 +378,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
rdclass = dns.rdataclass.from_text(arg)
|
rdclass = dns.rdataclass.from_text(arg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"dns lookup illegal CLASS: {to_native(e)}")
|
raise AnsibleError(f"dns lookup illegal CLASS: {e}")
|
||||||
elif opt == 'retry_servfail':
|
elif opt == 'retry_servfail':
|
||||||
myres.retry_servfail = boolean(arg)
|
myres.retry_servfail = boolean(arg)
|
||||||
elif opt == 'fail_on_error':
|
elif opt == 'fail_on_error':
|
||||||
|
@ -416,7 +415,7 @@ class LookupModule(LookupBase):
|
||||||
except dns.exception.SyntaxError:
|
except dns.exception.SyntaxError:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"dns.reversename unhandled exception {to_native(e)}")
|
raise AnsibleError(f"dns.reversename unhandled exception {e}")
|
||||||
domains = reversed_domains
|
domains = reversed_domains
|
||||||
|
|
||||||
if len(domains) > 1:
|
if len(domains) > 1:
|
||||||
|
@ -445,20 +444,20 @@ class LookupModule(LookupBase):
|
||||||
ret.append(rd)
|
ret.append(rd)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
raise AnsibleError(f"Lookup failed: {err}")
|
||||||
ret.append(str(err))
|
ret.append(str(err))
|
||||||
|
|
||||||
except dns.resolver.NXDOMAIN as err:
|
except dns.resolver.NXDOMAIN as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
raise AnsibleError(f"Lookup failed: {err}")
|
||||||
if not real_empty:
|
if not real_empty:
|
||||||
ret.append('NXDOMAIN')
|
ret.append('NXDOMAIN')
|
||||||
except (dns.resolver.NoAnswer, dns.resolver.Timeout, dns.resolver.NoNameservers) as err:
|
except (dns.resolver.NoAnswer, dns.resolver.Timeout, dns.resolver.NoNameservers) as err:
|
||||||
if fail_on_error:
|
if fail_on_error:
|
||||||
raise AnsibleError(f"Lookup failed: {str(err)}")
|
raise AnsibleError(f"Lookup failed: {err}")
|
||||||
if not real_empty:
|
if not real_empty:
|
||||||
ret.append("")
|
ret.append("")
|
||||||
except dns.exception.DNSException as err:
|
except dns.exception.DNSException as err:
|
||||||
raise AnsibleError(f"dns.resolver unhandled exception {to_native(err)}")
|
raise AnsibleError(f"dns.resolver unhandled exception {err}")
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -64,7 +64,6 @@ except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ansible.errors import AnsibleError
|
from ansible.errors import AnsibleError
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
|
||||||
from ansible.plugins.lookup import LookupBase
|
from ansible.plugins.lookup import LookupBase
|
||||||
|
|
||||||
# ==============================================================
|
# ==============================================================
|
||||||
|
@ -108,7 +107,7 @@ class LookupModule(LookupBase):
|
||||||
continue
|
continue
|
||||||
string = ''
|
string = ''
|
||||||
except DNSException as e:
|
except DNSException as e:
|
||||||
raise AnsibleError(f"dns.resolver unhandled exception {to_native(e)}")
|
raise AnsibleError(f"dns.resolver unhandled exception {e}")
|
||||||
|
|
||||||
ret.append(''.join(string))
|
ret.append(''.join(string))
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ def etcd3_client(client_params):
|
||||||
etcd = etcd3.client(**client_params)
|
etcd = etcd3.client(**client_params)
|
||||||
etcd.status()
|
etcd.status()
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
raise AnsibleLookupError(f'Cannot connect to etcd cluster: {to_native(exp)}')
|
raise AnsibleLookupError(f'Cannot connect to etcd cluster: {exp}')
|
||||||
return etcd
|
return etcd
|
||||||
|
|
||||||
|
|
||||||
|
@ -218,12 +218,12 @@ class LookupModule(LookupBase):
|
||||||
if val and meta:
|
if val and meta:
|
||||||
ret.append({'key': to_native(meta.key), 'value': to_native(val)})
|
ret.append({'key': to_native(meta.key), 'value': to_native(val)})
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
display.warning(f'Caught except during etcd3.get_prefix: {to_native(exp)}')
|
display.warning(f'Caught except during etcd3.get_prefix: {exp}')
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
val, meta = etcd.get(term)
|
val, meta = etcd.get(term)
|
||||||
if val and meta:
|
if val and meta:
|
||||||
ret.append({'key': to_native(meta.key), 'value': to_native(val)})
|
ret.append({'key': to_native(meta.key), 'value': to_native(val)})
|
||||||
except Exception as exp:
|
except Exception as exp:
|
||||||
display.warning(f'Caught except during etcd3.get: {to_native(exp)}')
|
display.warning(f'Caught except during etcd3.get: {exp}')
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -57,7 +57,7 @@ class LookupModule(LookupBase):
|
||||||
|
|
||||||
def run(self, terms, variables=None, **kwargs):
|
def run(self, terms, variables=None, **kwargs):
|
||||||
if not HAS_KEYRING:
|
if not HAS_KEYRING:
|
||||||
raise AnsibleError(u"Can't LOOKUP(keyring): missing required python library 'keyring'")
|
raise AnsibleError("Can't LOOKUP(keyring): missing required python library 'keyring'")
|
||||||
|
|
||||||
self.set_options(var_options=variables, direct=kwargs)
|
self.set_options(var_options=variables, direct=kwargs)
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ class LookupModule(LookupBase):
|
||||||
try:
|
try:
|
||||||
env = lmdb.open(str(db), readonly=True)
|
env = lmdb.open(str(db), readonly=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise AnsibleError(f"LMDB can't open database {db}: {to_native(e)}")
|
raise AnsibleError(f"LMDB cannot open database {db}: {e}")
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
if len(terms) == 0:
|
if len(terms) == 0:
|
||||||
|
|
|
@ -121,13 +121,13 @@ class ManifoldApiClient(object):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ApiError(f'JSON response can\'t be parsed while requesting {url}:\n{data}')
|
raise ApiError(f'JSON response can\'t be parsed while requesting {url}:\n{data}')
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
raise ApiError(f'Server returned: {str(e)} while requesting {url}:\n{e.read()}')
|
raise ApiError(f'Server returned: {e} while requesting {url}:\n{e.read()}')
|
||||||
except URLError as e:
|
except URLError as e:
|
||||||
raise ApiError(f'Failed lookup url for {url} : {str(e)}')
|
raise ApiError(f'Failed lookup url for {url} : {e}')
|
||||||
except SSLValidationError as e:
|
except SSLValidationError as e:
|
||||||
raise ApiError(f'Error validating the server\'s certificate for {url}: {str(e)}')
|
raise ApiError(f'Error validating the server\'s certificate for {url}: {e}')
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
raise ApiError(f'Error connecting to {url}: {str(e)}')
|
raise ApiError(f'Error connecting to {url}: {e}')
|
||||||
|
|
||||||
def get_resources(self, team_id=None, project_id=None, label=None):
|
def get_resources(self, team_id=None, project_id=None, label=None):
|
||||||
"""
|
"""
|
||||||
|
@ -270,7 +270,7 @@ class LookupModule(LookupBase):
|
||||||
ret = [credentials]
|
ret = [credentials]
|
||||||
return ret
|
return ret
|
||||||
except ApiError as e:
|
except ApiError as e:
|
||||||
raise AnsibleError(f'API Error: {str(e)}')
|
raise AnsibleError(f'API Error: {e}')
|
||||||
except AnsibleError as e:
|
except AnsibleError as e:
|
||||||
raise e
|
raise e
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
@ -169,7 +169,7 @@ class OnePassCLIBase(with_metaclass(abc.ABCMeta, object)):
|
||||||
rc = p.wait()
|
rc = p.wait()
|
||||||
|
|
||||||
if not ignore_errors and rc != expected_rc:
|
if not ignore_errors and rc != expected_rc:
|
||||||
raise AnsibleLookupError(to_text(err))
|
raise AnsibleLookupError(str(err))
|
||||||
|
|
||||||
return rc, out, err
|
return rc, out, err
|
||||||
|
|
||||||
|
|
|
@ -325,12 +325,12 @@ class TSSClient(object):
|
||||||
if i['isFile']:
|
if i['isFile']:
|
||||||
try:
|
try:
|
||||||
file_content = i['itemValue'].content
|
file_content = i['itemValue'].content
|
||||||
with open(os.path.join(file_download_path, f"{str(obj['id'])}_{i['slug']}"), "wb") as f:
|
with open(os.path.join(file_download_path, f"{obj['id']}_{i['slug']}"), "wb") as f:
|
||||||
f.write(file_content)
|
f.write(file_content)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise AnsibleOptionsError(f"Failed to download {str(i['slug'])}")
|
raise AnsibleOptionsError(f"Failed to download {i['slug']}")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
display.warning(f"Could not read file content for {str(i['slug'])}")
|
display.warning(f"Could not read file content for {i['slug']}")
|
||||||
finally:
|
finally:
|
||||||
i['itemValue'] = "*** Not Valid For Display ***"
|
i['itemValue'] = "*** Not Valid For Display ***"
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -15,7 +15,7 @@ from ansible.utils.unsafe_proxy import (
|
||||||
wrap_var as _make_unsafe,
|
wrap_var as _make_unsafe,
|
||||||
)
|
)
|
||||||
|
|
||||||
_RE_TEMPLATE_CHARS = re.compile(u'[{}]')
|
_RE_TEMPLATE_CHARS = re.compile('[{}]')
|
||||||
_RE_TEMPLATE_CHARS_BYTES = re.compile(b'[{}]')
|
_RE_TEMPLATE_CHARS_BYTES = re.compile(b'[{}]')
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue