mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-29 11:40:22 -07:00
Callbacks: use ansible-core's version instead of trying to extract it (#10193)
* Use ansible-core's version instead of trying to extract it. * Adjust tests.
This commit is contained in:
parent
624a8aa120
commit
d922eaebce
7 changed files with 16 additions and 46 deletions
6
changelogs/fragments/10193-callback-ansible_version.yml
Normal file
6
changelogs/fragments/10193-callback-ansible_version.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
minor_changes:
|
||||
- "elastic callback plugin - instead of trying to extract the ansible-core version from task data, use ansible-core's actual version (https://github.com/ansible-collections/community.general/pull/10193)."
|
||||
- "loganalytics callback plugin - instead of trying to extract the ansible-core version from task data, use ansible-core's actual version (https://github.com/ansible-collections/community.general/pull/10193)."
|
||||
- "opentelemetry callback plugin - instead of trying to extract the ansible-core version from task data, use ansible-core's actual version (https://github.com/ansible-collections/community.general/pull/10193)."
|
||||
- "splunk callback plugin - instead of trying to extract the ansible-core version from task data, use ansible-core's actual version (https://github.com/ansible-collections/community.general/pull/10193)."
|
||||
- "sumologic callback plugin - instead of trying to extract the ansible-core version from task data, use ansible-core's actual version (https://github.com/ansible-collections/community.general/pull/10193)."
|
|
@ -87,6 +87,7 @@ from contextlib import closing
|
|||
from os.path import basename
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleRuntimeError
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
||||
|
@ -140,7 +141,6 @@ class HostData:
|
|||
class ElasticSource(object):
|
||||
def __init__(self, display):
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = None
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
try:
|
||||
|
@ -183,9 +183,6 @@ class ElasticSource(object):
|
|||
|
||||
task = tasks_data[task_uuid]
|
||||
|
||||
if self.ansible_version is None and result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
task.add_host(HostData(host_uuid, host_name, status, result))
|
||||
|
||||
def generate_distributed_traces(self, tasks_data, status, end_time, traceparent, apm_service_name,
|
||||
|
@ -209,8 +206,7 @@ class ElasticSource(object):
|
|||
else:
|
||||
apm_cli.begin_transaction("Session", start=parent_start_time)
|
||||
# Populate trace metadata attributes
|
||||
if self.ansible_version is not None:
|
||||
label(ansible_version=self.ansible_version)
|
||||
label(ansible_version=ansible_version)
|
||||
label(ansible_session=self.session, ansible_host_name=self.host, ansible_host_user=self.user)
|
||||
if self.ip_address is not None:
|
||||
label(ansible_host_ip=self.ip_address)
|
||||
|
|
|
@ -62,6 +62,7 @@ import getpass
|
|||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
@ -75,7 +76,6 @@ class AzureLogAnalyticsSource(object):
|
|||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.user = getpass.getuser()
|
||||
|
@ -102,10 +102,6 @@ class AzureLogAnalyticsSource(object):
|
|||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
|
@ -119,7 +115,7 @@ class AzureLogAnalyticsSource(object):
|
|||
data['host'] = self.host
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
|
|
@ -143,6 +143,7 @@ from collections import OrderedDict
|
|||
from os.path import basename
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.six import raise_from
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
@ -212,7 +213,6 @@ class HostData:
|
|||
class OpenTelemetrySource(object):
|
||||
def __init__(self, display):
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = None
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
try:
|
||||
|
@ -260,9 +260,6 @@ class OpenTelemetrySource(object):
|
|||
|
||||
task = tasks_data[task_uuid]
|
||||
|
||||
if self.ansible_version is None and hasattr(result, '_task_fields') and result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
task.dump = dump
|
||||
task.add_host(HostData(host_uuid, host_name, status, result))
|
||||
|
||||
|
@ -310,8 +307,7 @@ class OpenTelemetrySource(object):
|
|||
start_time=parent_start_time, kind=SpanKind.SERVER) as parent:
|
||||
parent.set_status(status)
|
||||
# Populate trace metadata attributes
|
||||
if self.ansible_version is not None:
|
||||
parent.set_attribute("ansible.version", self.ansible_version)
|
||||
parent.set_attribute("ansible.version", ansible_version)
|
||||
parent.set_attribute("ansible.session", self.session)
|
||||
parent.set_attribute("ansible.host.name", self.host)
|
||||
if self.ip_address is not None:
|
||||
|
|
|
@ -91,6 +91,7 @@ import getpass
|
|||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
@ -104,7 +105,6 @@ class SplunkHTTPCollectorSource(object):
|
|||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.ip_address = socket.gethostbyname(socket.gethostname())
|
||||
|
@ -114,10 +114,6 @@ class SplunkHTTPCollectorSource(object):
|
|||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
|
@ -143,7 +139,7 @@ class SplunkHTTPCollectorSource(object):
|
|||
data['ip_address'] = self.ip_address
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
|
|
@ -48,6 +48,7 @@ import getpass
|
|||
|
||||
from os.path import basename
|
||||
|
||||
from ansible.module_utils.ansible_release import __version__ as ansible_version
|
||||
from ansible.module_utils.urls import open_url
|
||||
from ansible.parsing.ajson import AnsibleJSONEncoder
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
|
@ -61,7 +62,6 @@ class SumologicHTTPCollectorSource(object):
|
|||
def __init__(self):
|
||||
self.ansible_check_mode = False
|
||||
self.ansible_playbook = ""
|
||||
self.ansible_version = ""
|
||||
self.session = str(uuid.uuid4())
|
||||
self.host = socket.gethostname()
|
||||
self.ip_address = socket.gethostbyname(socket.gethostname())
|
||||
|
@ -71,10 +71,6 @@ class SumologicHTTPCollectorSource(object):
|
|||
if result._task_fields['args'].get('_ansible_check_mode') is True:
|
||||
self.ansible_check_mode = True
|
||||
|
||||
if result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = \
|
||||
result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
if result._task._role:
|
||||
ansible_role = str(result._task._role)
|
||||
else:
|
||||
|
@ -92,7 +88,7 @@ class SumologicHTTPCollectorSource(object):
|
|||
data['ip_address'] = self.ip_address
|
||||
data['user'] = self.user
|
||||
data['runtime'] = runtime
|
||||
data['ansible_version'] = self.ansible_version
|
||||
data['ansible_version'] = ansible_version
|
||||
data['ansible_check_mode'] = self.ansible_check_mode
|
||||
data['ansible_host'] = result._host.name
|
||||
data['ansible_playbook'] = self.ansible_playbook
|
||||
|
|
|
@ -95,22 +95,6 @@ class TestOpentelemetry(unittest.TestCase):
|
|||
self.assertEqual(host_data.uuid, 'include')
|
||||
self.assertEqual(host_data.name, 'include')
|
||||
self.assertEqual(host_data.status, 'ok')
|
||||
self.assertEqual(self.opentelemetry.ansible_version, None)
|
||||
|
||||
def test_finish_task_include_with_ansible_version(self):
|
||||
task_fields = {'args': {'_ansible_version': '1.2.3'}}
|
||||
result = TaskResult(host=None, task=self.mock_task, return_data={}, task_fields=task_fields)
|
||||
tasks_data = OrderedDict()
|
||||
tasks_data['myuuid'] = self.my_task
|
||||
|
||||
self.opentelemetry.finish_task(
|
||||
tasks_data,
|
||||
'ok',
|
||||
result,
|
||||
""
|
||||
)
|
||||
|
||||
self.assertEqual(self.opentelemetry.ansible_version, '1.2.3')
|
||||
|
||||
def test_get_error_message(self):
|
||||
test_cases = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue