diff --git a/changelogs/fragments/5240-unused-imports.yaml b/changelogs/fragments/5240-unused-imports.yaml new file mode 100644 index 0000000000..b615b0c6a3 --- /dev/null +++ b/changelogs/fragments/5240-unused-imports.yaml @@ -0,0 +1,3 @@ +minor_changes: + - ali_instance - minor refactor when checking for installed dependency (https://github.com/ansible-collections/community.general/pull/5240). + - ali_instance_info - minor refactor when checking for installed dependency (https://github.com/ansible-collections/community.general/pull/5240). diff --git a/plugins/module_utils/alicloud_ecs.py b/plugins/module_utils/alicloud_ecs.py index 8532d25c1c..8210793c76 100644 --- a/plugins/module_utils/alicloud_ecs.py +++ b/plugins/module_utils/alicloud_ecs.py @@ -15,6 +15,7 @@ __metaclass__ = type import os import json +import traceback from ansible.module_utils.basic import env_fallback try: @@ -28,8 +29,11 @@ try: import footmark.dns import footmark.ram import footmark.market + + FOOTMARK_IMP_ERR = None HAS_FOOTMARK = True except ImportError: + FOOTMARK_IMP_ERR = traceback.format_exc() HAS_FOOTMARK = False diff --git a/plugins/modules/cloud/alicloud/ali_instance.py b/plugins/modules/cloud/alicloud/ali_instance.py index 40fced0866..4acec0a109 100644 --- a/plugins/modules/cloud/alicloud/ali_instance.py +++ b/plugins/modules/cloud/alicloud/ali_instance.py @@ -617,18 +617,10 @@ ids: import re import time -import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible_collections.community.general.plugins.module_utils.alicloud_ecs import ecs_argument_spec, ecs_connect - -HAS_FOOTMARK = False -FOOTMARK_IMP_ERR = None -try: - from footmark.exception import ECSResponseError - HAS_FOOTMARK = True -except ImportError: - FOOTMARK_IMP_ERR = traceback.format_exc() - HAS_FOOTMARK = False +from ansible_collections.community.general.plugins.module_utils.alicloud_ecs import ( + ecs_argument_spec, ecs_connect, FOOTMARK_IMP_ERR, HAS_FOOTMARK +) def get_instances_info(connection, ids): diff --git a/plugins/modules/cloud/alicloud/ali_instance_info.py b/plugins/modules/cloud/alicloud/ali_instance_info.py index e40605fe06..4b758477a3 100644 --- a/plugins/modules/cloud/alicloud/ali_instance_info.py +++ b/plugins/modules/cloud/alicloud/ali_instance_info.py @@ -341,18 +341,10 @@ ids: sample: [i-12345er, i-3245fs] ''' -import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible_collections.community.general.plugins.module_utils.alicloud_ecs import ecs_argument_spec, ecs_connect - -HAS_FOOTMARK = False -FOOTMARK_IMP_ERR = None -try: - from footmark.exception import ECSResponseError - HAS_FOOTMARK = True -except ImportError: - FOOTMARK_IMP_ERR = traceback.format_exc() - HAS_FOOTMARK = False +from ansible_collections.community.general.plugins.module_utils.alicloud_ecs import ( + ecs_argument_spec, ecs_connect, FOOTMARK_IMP_ERR, HAS_FOOTMARK +) def main(): diff --git a/plugins/modules/cloud/misc/proxmox.py b/plugins/modules/cloud/misc/proxmox.py index 63e31d7a43..c6fbf24f9b 100644 --- a/plugins/modules/cloud/misc/proxmox.py +++ b/plugins/modules/cloud/misc/proxmox.py @@ -390,11 +390,10 @@ EXAMPLES = r''' ''' import time -import traceback from ansible_collections.community.general.plugins.module_utils.version import LooseVersion -from ansible.module_utils.basic import AnsibleModule, env_fallback +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils.proxmox import ( diff --git a/plugins/modules/cloud/misc/proxmox_domain_info.py b/plugins/modules/cloud/misc/proxmox_domain_info.py index 4249a8010d..2cabf5b3c7 100644 --- a/plugins/modules/cloud/misc/proxmox_domain_info.py +++ b/plugins/modules/cloud/misc/proxmox_domain_info.py @@ -75,7 +75,7 @@ proxmox_domains: ''' -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import ( proxmox_auth_argument_spec, ProxmoxAnsible) diff --git a/plugins/modules/cloud/misc/proxmox_group_info.py b/plugins/modules/cloud/misc/proxmox_group_info.py index 48a411f3ad..d2d4491ce2 100644 --- a/plugins/modules/cloud/misc/proxmox_group_info.py +++ b/plugins/modules/cloud/misc/proxmox_group_info.py @@ -72,7 +72,7 @@ proxmox_groups: ''' -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import ( proxmox_auth_argument_spec, ProxmoxAnsible) diff --git a/plugins/modules/cloud/misc/proxmox_kvm.py b/plugins/modules/cloud/misc/proxmox_kvm.py index 1180c56173..15a59be815 100644 --- a/plugins/modules/cloud/misc/proxmox_kvm.py +++ b/plugins/modules/cloud/misc/proxmox_kvm.py @@ -803,14 +803,12 @@ msg: import re import time -import traceback from ansible.module_utils.six.moves.urllib.parse import quote from ansible_collections.community.general.plugins.module_utils.version import LooseVersion from ansible_collections.community.general.plugins.module_utils.proxmox import (proxmox_auth_argument_spec, ProxmoxAnsible) -from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.common.text.converters import to_native +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.parsing.convert_bool import boolean diff --git a/plugins/modules/cloud/misc/proxmox_nic.py b/plugins/modules/cloud/misc/proxmox_nic.py index eec32bee3c..49f7f91bcd 100644 --- a/plugins/modules/cloud/misc/proxmox_nic.py +++ b/plugins/modules/cloud/misc/proxmox_nic.py @@ -137,7 +137,7 @@ msg: sample: "Nic net0 unchanged on VM with vmid 103" ''' -from ansible.module_utils.basic import AnsibleModule, env_fallback +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import (proxmox_auth_argument_spec, ProxmoxAnsible) diff --git a/plugins/modules/cloud/misc/proxmox_snap.py b/plugins/modules/cloud/misc/proxmox_snap.py index b90b51b34c..93fa8d346f 100644 --- a/plugins/modules/cloud/misc/proxmox_snap.py +++ b/plugins/modules/cloud/misc/proxmox_snap.py @@ -102,9 +102,9 @@ RETURN = r'''#''' import time import traceback -from ansible.module_utils.basic import AnsibleModule, missing_required_lib, env_fallback +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.converters import to_native -from ansible_collections.community.general.plugins.module_utils.proxmox import (proxmox_auth_argument_spec, ProxmoxAnsible, HAS_PROXMOXER, PROXMOXER_IMP_ERR) +from ansible_collections.community.general.plugins.module_utils.proxmox import (proxmox_auth_argument_spec, ProxmoxAnsible) class ProxmoxSnapAnsible(ProxmoxAnsible): diff --git a/plugins/modules/cloud/misc/proxmox_storage_info.py b/plugins/modules/cloud/misc/proxmox_storage_info.py index bbc25529a9..a98d3794a9 100644 --- a/plugins/modules/cloud/misc/proxmox_storage_info.py +++ b/plugins/modules/cloud/misc/proxmox_storage_info.py @@ -110,7 +110,7 @@ proxmox_storages: ''' -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import ( proxmox_auth_argument_spec, ProxmoxAnsible, proxmox_to_ansible_bool) diff --git a/plugins/modules/cloud/misc/proxmox_tasks_info.py b/plugins/modules/cloud/misc/proxmox_tasks_info.py index 252d3411d0..c0a3dc6886 100644 --- a/plugins/modules/cloud/misc/proxmox_tasks_info.py +++ b/plugins/modules/cloud/misc/proxmox_tasks_info.py @@ -115,7 +115,7 @@ msg: sample: 'Task: UPID:xyz:xyz does not exist on node: proxmoxnode' ''' -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import ( proxmox_auth_argument_spec, ProxmoxAnsible) diff --git a/plugins/modules/cloud/misc/proxmox_template.py b/plugins/modules/cloud/misc/proxmox_template.py index 975949efe3..ab6e2d88e8 100644 --- a/plugins/modules/cloud/misc/proxmox_template.py +++ b/plugins/modules/cloud/misc/proxmox_template.py @@ -117,7 +117,7 @@ EXAMPLES = ''' import os import time -from ansible.module_utils.basic import AnsibleModule, env_fallback +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import (proxmox_auth_argument_spec, ProxmoxAnsible) diff --git a/plugins/modules/cloud/misc/proxmox_user_info.py b/plugins/modules/cloud/misc/proxmox_user_info.py index 134fdc1e09..f1b3b881c9 100644 --- a/plugins/modules/cloud/misc/proxmox_user_info.py +++ b/plugins/modules/cloud/misc/proxmox_user_info.py @@ -155,7 +155,7 @@ proxmox_users: ''' -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.proxmox import ( proxmox_auth_argument_spec, ProxmoxAnsible, proxmox_to_ansible_bool) diff --git a/plugins/modules/database/misc/redis.py b/plugins/modules/database/misc/redis.py index 36e7df3883..298b3aaf8c 100644 --- a/plugins/modules/database/misc/redis.py +++ b/plugins/modules/database/misc/redis.py @@ -139,7 +139,7 @@ except ImportError: else: redis_found = True -from ansible.module_utils.basic import AnsibleModule, missing_required_lib +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.common.text.formatters import human_to_bytes from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils.redis import ( diff --git a/plugins/modules/monitoring/airbrake_deployment.py b/plugins/modules/monitoring/airbrake_deployment.py index 2b3b1832f3..2fb5b58737 100644 --- a/plugins/modules/monitoring/airbrake_deployment.py +++ b/plugins/modules/monitoring/airbrake_deployment.py @@ -95,7 +95,6 @@ EXAMPLES = ''' from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url -from ansible.module_utils.six.moves.urllib.parse import urlencode # =========================================== diff --git a/plugins/modules/monitoring/datadog/datadog_downtime.py b/plugins/modules/monitoring/datadog/datadog_downtime.py index 2226d0c678..8a1acf7e83 100644 --- a/plugins/modules/monitoring/datadog/datadog_downtime.py +++ b/plugins/modules/monitoring/datadog/datadog_downtime.py @@ -151,7 +151,6 @@ import traceback from ansible.module_utils.basic import AnsibleModule, missing_required_lib # Import Datadog -from ansible.module_utils.common.text.converters import to_native DATADOG_IMP_ERR = None HAS_DATADOG = True diff --git a/plugins/modules/remote_management/imc/imc_rest.py b/plugins/modules/remote_management/imc/imc_rest.py index 4259558053..4d90bcc54d 100644 --- a/plugins/modules/remote_management/imc/imc_rest.py +++ b/plugins/modules/remote_management/imc/imc_rest.py @@ -264,7 +264,6 @@ output: import datetime import os import traceback -from functools import partial LXML_ETREE_IMP_ERR = None try: diff --git a/plugins/modules/remote_management/redfish/ilo_redfish_info.py b/plugins/modules/remote_management/redfish/ilo_redfish_info.py index d5ff123564..4611e620d5 100644 --- a/plugins/modules/remote_management/redfish/ilo_redfish_info.py +++ b/plugins/modules/remote_management/redfish/ilo_redfish_info.py @@ -106,7 +106,6 @@ CATEGORY_COMMANDS_DEFAULT = { } from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible_collections.community.general.plugins.module_utils.ilo_redfish_utils import iLORedfishUtils diff --git a/plugins/modules/system/sap_task_list_execute.py b/plugins/modules/system/sap_task_list_execute.py index 52c2361414..29936b8483 100644 --- a/plugins/modules/system/sap_task_list_execute.py +++ b/plugins/modules/system/sap_task_list_execute.py @@ -179,7 +179,6 @@ out: ''' from ansible.module_utils.basic import AnsibleModule, missing_required_lib -from ansible.module_utils.json_utils import json import traceback try: from pyrfc import Connection diff --git a/plugins/modules/web_infrastructure/rundeck_job_executions_info.py b/plugins/modules/web_infrastructure/rundeck_job_executions_info.py index bafb8f78e5..e6c9239d75 100644 --- a/plugins/modules/web_infrastructure/rundeck_job_executions_info.py +++ b/plugins/modules/web_infrastructure/rundeck_job_executions_info.py @@ -131,7 +131,6 @@ executions: import json from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.six.moves.urllib.parse import quote from ansible_collections.community.general.plugins.module_utils.rundeck import ( api_argument_spec, diff --git a/plugins/modules/web_infrastructure/rundeck_job_run.py b/plugins/modules/web_infrastructure/rundeck_job_run.py index 936d490349..0416d86fa7 100644 --- a/plugins/modules/web_infrastructure/rundeck_job_run.py +++ b/plugins/modules/web_infrastructure/rundeck_job_run.py @@ -174,12 +174,10 @@ execution_info: ''' # Modules import -import json from datetime import datetime, timedelta from time import sleep from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.six.moves.urllib.parse import quote from ansible_collections.community.general.plugins.module_utils.rundeck import ( api_argument_spec,