summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2018-11-20 17:06:51 -0600
committerGitHub <noreply@github.com>2018-11-20 17:06:51 -0600
commit9773a1f2896a914d237cb9926e3b5cdc0f004d1a (patch)
tree50d16f7f19b8fcc81f11ce220b9af22ab19c9709
parent54a2f21f93c54c4a10e378e500efcc52999d6408 (diff)
downloadansible-9773a1f2896a914d237cb9926e3b5cdc0f004d1a.tar.gz
Add a Singleton metaclass, use it with Display (#48935)
* Add a Singleton class, use it with Display * update six import * Move remaining failes to display singleton * Fix rebase issues * Singleton improvements * Add code-smell for 'from __main__ import display'. ci_complete * s/self/cls/g * Add docs for no-main-display * Address linting issues * Add changelog fragment. ci_complete * Implement reentrant lock for class instantiation in Singleton * Add Display singleton porting guide
-rw-r--r--changelogs/fragments/display-singleton.yaml2
-rw-r--r--docs/docsite/rst/dev_guide/developing_plugins.rst7
-rw-r--r--docs/docsite/rst/dev_guide/testing/sanity/no-main-display.rst12
-rw-r--r--docs/docsite/rst/porting_guides/porting_guide_2.0.rst4
-rw-r--r--docs/docsite/rst/porting_guides/porting_guide_2.8.rst23
-rw-r--r--lib/ansible/cli/__init__.py7
-rw-r--r--lib/ansible/cli/adhoc.py11
-rw-r--r--lib/ansible/cli/config.py8
-rw-r--r--lib/ansible/cli/console.py7
-rw-r--r--lib/ansible/cli/doc.py7
-rw-r--r--lib/ansible/cli/galaxy.py7
-rw-r--r--lib/ansible/cli/inventory.py7
-rw-r--r--lib/ansible/cli/playbook.py9
-rw-r--r--lib/ansible/cli/pull.py10
-rw-r--r--lib/ansible/cli/vault.py7
-rw-r--r--lib/ansible/constants.py8
-rw-r--r--lib/ansible/executor/module_common.py7
-rw-r--r--lib/ansible/executor/play_iterator.py7
-rw-r--r--lib/ansible/executor/playbook_executor.py7
-rw-r--r--lib/ansible/executor/process/worker.py9
-rw-r--r--lib/ansible/executor/task_executor.py7
-rw-r--r--lib/ansible/executor/task_queue_manager.py9
-rw-r--r--lib/ansible/galaxy/api.py7
-rw-r--r--lib/ansible/galaxy/login.py7
-rw-r--r--lib/ansible/galaxy/role.py7
-rw-r--r--lib/ansible/galaxy/token.py8
-rw-r--r--lib/ansible/inventory/data.py7
-rw-r--r--lib/ansible/inventory/manager.py7
-rw-r--r--lib/ansible/parsing/dataloader.py7
-rw-r--r--lib/ansible/parsing/plugin_docs.py7
-rw-r--r--lib/ansible/parsing/vault/__init__.py7
-rw-r--r--lib/ansible/parsing/yaml/constructor.py7
-rw-r--r--lib/ansible/playbook/__init__.py7
-rw-r--r--lib/ansible/playbook/base.py7
-rw-r--r--lib/ansible/playbook/become.py7
-rw-r--r--lib/ansible/playbook/conditional.py8
-rw-r--r--lib/ansible/playbook/helpers.py7
-rw-r--r--lib/ansible/playbook/included_file.py7
-rw-r--r--lib/ansible/playbook/play.py7
-rw-r--r--lib/ansible/playbook/play_context.py7
-rw-r--r--lib/ansible/playbook/role/definition.py10
-rw-r--r--lib/ansible/playbook/role/requirement.py9
-rw-r--r--lib/ansible/playbook/role_include.py10
-rw-r--r--lib/ansible/playbook/task.py10
-rw-r--r--lib/ansible/playbook/task_include.py9
-rw-r--r--lib/ansible/plugins/__init__.py7
-rw-r--r--lib/ansible/plugins/action/__init__.py7
-rw-r--r--lib/ansible/plugins/action/add_host.py7
-rw-r--r--lib/ansible/plugins/action/aireos.py8
-rw-r--r--lib/ansible/plugins/action/aruba.py7
-rw-r--r--lib/ansible/plugins/action/asa.py8
-rw-r--r--lib/ansible/plugins/action/bigip.py7
-rw-r--r--lib/ansible/plugins/action/bigiq.py7
-rw-r--r--lib/ansible/plugins/action/ce.py8
-rw-r--r--lib/ansible/plugins/action/cnos.py8
-rw-r--r--lib/ansible/plugins/action/dellos10.py7
-rw-r--r--lib/ansible/plugins/action/dellos6.py7
-rw-r--r--lib/ansible/plugins/action/dellos9.py7
-rw-r--r--lib/ansible/plugins/action/enos.py8
-rw-r--r--lib/ansible/plugins/action/eos.py7
-rw-r--r--lib/ansible/plugins/action/fetch.py7
-rw-r--r--lib/ansible/plugins/action/ios.py7
-rw-r--r--lib/ansible/plugins/action/iosxr.py7
-rw-r--r--lib/ansible/plugins/action/ironware.py7
-rw-r--r--lib/ansible/plugins/action/junos.py8
-rw-r--r--lib/ansible/plugins/action/net_base.py7
-rw-r--r--lib/ansible/plugins/action/net_get.py7
-rw-r--r--lib/ansible/plugins/action/net_put.py7
-rw-r--r--lib/ansible/plugins/action/netconf.py7
-rw-r--r--lib/ansible/plugins/action/nxos.py7
-rw-r--r--lib/ansible/plugins/action/package.py7
-rw-r--r--lib/ansible/plugins/action/pause.py7
-rw-r--r--lib/ansible/plugins/action/reboot.py8
-rw-r--r--lib/ansible/plugins/action/sros.py7
-rw-r--r--lib/ansible/plugins/action/telnet.py7
-rw-r--r--lib/ansible/plugins/action/vyos.py7
-rw-r--r--lib/ansible/plugins/action/wait_for_connection.py7
-rw-r--r--lib/ansible/plugins/action/win_reboot.py7
-rw-r--r--lib/ansible/plugins/action/win_updates.py7
-rw-r--r--lib/ansible/plugins/action/yum.py7
-rw-r--r--lib/ansible/plugins/cache/__init__.py7
-rw-r--r--lib/ansible/plugins/callback/__init__.py7
-rw-r--r--lib/ansible/plugins/callback/dense.py10
-rw-r--r--lib/ansible/plugins/cliconf/__init__.py8
-rw-r--r--lib/ansible/plugins/cliconf/routeros.py7
-rw-r--r--lib/ansible/plugins/connection/__init__.py7
-rw-r--r--lib/ansible/plugins/connection/buildah.py8
-rw-r--r--lib/ansible/plugins/connection/chroot.py8
-rw-r--r--lib/ansible/plugins/connection/docker.py8
-rw-r--r--lib/ansible/plugins/connection/funcd.py7
-rw-r--r--lib/ansible/plugins/connection/httpapi.py7
-rw-r--r--lib/ansible/plugins/connection/iocage.py7
-rw-r--r--lib/ansible/plugins/connection/jail.py7
-rw-r--r--lib/ansible/plugins/connection/kubectl.py8
-rw-r--r--lib/ansible/plugins/connection/libvirt_lxc.py8
-rw-r--r--lib/ansible/plugins/connection/local.py8
-rw-r--r--lib/ansible/plugins/connection/napalm.py7
-rw-r--r--lib/ansible/plugins/connection/netconf.py7
-rw-r--r--lib/ansible/plugins/connection/network_cli.py7
-rw-r--r--lib/ansible/plugins/connection/paramiko_ssh.py7
-rw-r--r--lib/ansible/plugins/connection/persistent.py7
-rw-r--r--lib/ansible/plugins/connection/podman.py8
-rw-r--r--lib/ansible/plugins/connection/psrp.py7
-rw-r--r--lib/ansible/plugins/connection/qubes.py8
-rw-r--r--lib/ansible/plugins/connection/ssh.py7
-rw-r--r--lib/ansible/plugins/connection/winrm.py7
-rw-r--r--lib/ansible/plugins/connection/zone.py8
-rw-r--r--lib/ansible/plugins/filter/core.py7
-rw-r--r--lib/ansible/plugins/filter/mathstuff.py7
-rw-r--r--lib/ansible/plugins/filter/network.py11
-rw-r--r--lib/ansible/plugins/httpapi/eos.py7
-rw-r--r--lib/ansible/plugins/httpapi/ftd.py8
-rw-r--r--lib/ansible/plugins/httpapi/nxos.py7
-rw-r--r--lib/ansible/plugins/inventory/__init__.py7
-rw-r--r--lib/ansible/plugins/inventory/aws_ec2.py9
-rw-r--r--lib/ansible/plugins/inventory/toml.py8
-rw-r--r--lib/ansible/plugins/loader.py7
-rw-r--r--lib/ansible/plugins/lookup/__init__.py7
-rw-r--r--lib/ansible/plugins/lookup/aws_ssm.py9
-rw-r--r--lib/ansible/plugins/lookup/conjur_variable.py8
-rw-r--r--lib/ansible/plugins/lookup/cpm_metering.py7
-rw-r--r--lib/ansible/plugins/lookup/cyberarkpassword.py7
-rw-r--r--lib/ansible/plugins/lookup/file.py7
-rw-r--r--lib/ansible/plugins/lookup/filetree.py7
-rw-r--r--lib/ansible/plugins/lookup/grafana_dashboard.py7
-rw-r--r--lib/ansible/plugins/lookup/keyring.py10
-rw-r--r--lib/ansible/plugins/lookup/rabbitmq.py12
-rw-r--r--lib/ansible/plugins/lookup/template.py7
-rw-r--r--lib/ansible/plugins/lookup/url.py7
-rw-r--r--lib/ansible/plugins/netconf/ce.py7
-rw-r--r--lib/ansible/plugins/strategy/__init__.py8
-rw-r--r--lib/ansible/plugins/strategy/free.py8
-rw-r--r--lib/ansible/plugins/strategy/host_pinned.py8
-rw-r--r--lib/ansible/plugins/strategy/linear.py8
-rw-r--r--lib/ansible/plugins/terminal/junos.py8
-rw-r--r--lib/ansible/plugins/terminal/routeros.py7
-rw-r--r--lib/ansible/plugins/test/core.py7
-rw-r--r--lib/ansible/plugins/vars/__init__.py7
-rw-r--r--lib/ansible/template/__init__.py7
-rw-r--r--lib/ansible/utils/display.py4
-rw-r--r--lib/ansible/utils/encrypt.py7
-rw-r--r--lib/ansible/utils/jsonrpc.py8
-rw-r--r--lib/ansible/utils/plugin_docs.py7
-rw-r--r--lib/ansible/utils/singleton.py29
-rw-r--r--lib/ansible/vars/clean.py7
-rw-r--r--lib/ansible/vars/manager.py7
-rw-r--r--lib/ansible/vars/reserved.py7
-rw-r--r--test/sanity/code-smell/no-main-display.json10
-rwxr-xr-xtest/sanity/code-smell/no-main-display.py27
149 files changed, 407 insertions, 766 deletions
diff --git a/changelogs/fragments/display-singleton.yaml b/changelogs/fragments/display-singleton.yaml
new file mode 100644
index 0000000000..f7612aa3a5
--- /dev/null
+++ b/changelogs/fragments/display-singleton.yaml
@@ -0,0 +1,2 @@
+minor_changes:
+- Display - Add a ``Singleton`` metaclass and apply it to ``Display`` to remove the need of using ``__main__.Display`` as a pseudo singleton
diff --git a/docs/docsite/rst/dev_guide/developing_plugins.rst b/docs/docsite/rst/dev_guide/developing_plugins.rst
index ef72fa84b9..922021e83d 100644
--- a/docs/docsite/rst/dev_guide/developing_plugins.rst
+++ b/docs/docsite/rst/dev_guide/developing_plugins.rst
@@ -236,12 +236,9 @@ Here's a simple lookup plugin implementation --- this lookup returns the content
"""
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.plugins.lookup import LookupBase
+ from ansible.utils.display import Display
- try:
- from __main__ import display
- except ImportError:
- from ansible.utils.display import Display
- display = Display()
+ display = Display()
class LookupModule(LookupBase):
diff --git a/docs/docsite/rst/dev_guide/testing/sanity/no-main-display.rst b/docs/docsite/rst/dev_guide/testing/sanity/no-main-display.rst
new file mode 100644
index 0000000000..64c4be8c37
--- /dev/null
+++ b/docs/docsite/rst/dev_guide/testing/sanity/no-main-display.rst
@@ -0,0 +1,12 @@
+Sanity Tests » no-main-display
+==============================
+
+As of Ansible 2.8, ``Display`` should no longer be imported from ``__main__``.
+
+``Display`` is now a singleton and should be utilized like the following::
+
+ from ansible.utils.display import Display
+ display = Display()
+
+There is no longer a need to attempt ``from __main__ import display`` inside
+a ``try/except`` block.
diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.0.rst b/docs/docsite/rst/porting_guides/porting_guide_2.0.rst
index 9a84dd8ed9..022499be2b 100644
--- a/docs/docsite/rst/porting_guides/porting_guide_2.0.rst
+++ b/docs/docsite/rst/porting_guides/porting_guide_2.0.rst
@@ -332,8 +332,8 @@ As a simple example we are going to make a hybrid ``fileglob`` lookup plugin.
from ansible.utils import (listify_lookup_plugin_terms, path_dwim, warning)
except ImportError:
# ansible-2.0
- from __main__ import display
- warning = display.warning
+ from ansible.utils.display import Display
+ warning = Display().warning
class LookupModule(LookupBase):
diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.8.rst b/docs/docsite/rst/porting_guides/porting_guide_2.8.rst
index fd56b239c9..75b51df49d 100644
--- a/docs/docsite/rst/porting_guides/porting_guide_2.8.rst
+++ b/docs/docsite/rst/porting_guides/porting_guide_2.8.rst
@@ -124,7 +124,28 @@ Plugins
Porting custom scripts
======================
-No notable changes.
+Display class
+-------------
+
+As of Ansible 2.8, the ``Display`` class is now a "singleton". Instead of using ``__main__.display`` each file should
+import and instantiate ``ansible.utils.display.Display`` on it's own.
+
+**OLD** In Ansible 2.7 (and earlier) the following was used to access the ``display`` object:
+
+.. code-block:: python
+
+ try:
+ from __main__ import display
+ except ImportError:
+ from ansible.utils.display import Display
+ display = Display()
+
+**NEW** In Ansible 2.8 the following should be used:
+
+.. code-block:: python
+
+ from ansible.utils.display import Display
+ display = Display()
Networking
==========
diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py
index c09066e231..5ede397711 100644
--- a/lib/ansible/cli/__init__.py
+++ b/lib/ansible/cli/__init__.py
@@ -40,16 +40,13 @@ from ansible.module_utils.six import with_metaclass, string_types
from ansible.module_utils._text import to_bytes, to_text
from ansible.parsing.dataloader import DataLoader
from ansible.release import __version__
+from ansible.utils.display import Display
from ansible.utils.path import unfrackpath
from ansible.utils.vars import load_extra_vars, load_options_vars
from ansible.vars.manager import VariableManager
from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class SortedOptParser(optparse.OptionParser):
diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py
index 18427d8cae..0185f56ece 100644
--- a/lib/ansible/cli/adhoc.py
+++ b/lib/ansible/cli/adhoc.py
@@ -18,8 +18,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-########################################################
-
from ansible import constants as C
from ansible.cli import CLI
from ansible.errors import AnsibleError, AnsibleOptionsError
@@ -29,15 +27,10 @@ from ansible.parsing.splitter import parse_kv
from ansible.playbook import Playbook
from ansible.playbook.play import Play
from ansible.plugins.loader import get_all_plugin_loaders
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
+display = Display()
-########################################################
class AdHocCLI(CLI):
''' is an extra-simple tool/framework/API for doing 'remote things'.
diff --git a/lib/ansible/cli/config.py b/lib/ansible/cli/config.py
index f6f239845f..3109721360 100644
--- a/lib/ansible/cli/config.py
+++ b/lib/ansible/cli/config.py
@@ -16,14 +16,10 @@ from ansible.errors import AnsibleError, AnsibleOptionsError
from ansible.module_utils._text import to_native, to_text
from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.utils.color import stringc
+from ansible.utils.display import Display
from ansible.utils.path import unfrackpath
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ConfigCLI(CLI):
diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py
index f2349fc6b5..66563a5516 100644
--- a/lib/ansible/cli/console.py
+++ b/lib/ansible/cli/console.py
@@ -46,12 +46,9 @@ from ansible.playbook.play import Play
from ansible.plugins.loader import module_loader, fragment_loader
from ansible.utils import plugin_docs
from ansible.utils.color import stringc
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ConsoleCLI(CLI, cmd.Cmd):
diff --git a/lib/ansible/cli/doc.py b/lib/ansible/cli/doc.py
index df5cd33021..b911a6a801 100644
--- a/lib/ansible/cli/doc.py
+++ b/lib/ansible/cli/doc.py
@@ -35,13 +35,10 @@ from ansible.parsing.metadata import extract_metadata
from ansible.parsing.plugin_docs import read_docstub
from ansible.parsing.yaml.dumper import AnsibleDumper
from ansible.plugins.loader import action_loader, fragment_loader
+from ansible.utils.display import Display
from ansible.utils.plugin_docs import BLACKLIST, get_docstring
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class DocCLI(CLI):
diff --git a/lib/ansible/cli/galaxy.py b/lib/ansible/cli/galaxy.py
index a3ae8ee4bc..199e50b842 100644
--- a/lib/ansible/cli/galaxy.py
+++ b/lib/ansible/cli/galaxy.py
@@ -41,12 +41,9 @@ from ansible.galaxy.role import GalaxyRole
from ansible.galaxy.token import GalaxyToken
from ansible.module_utils._text import to_native, to_text
from ansible.playbook.role.requirement import RoleRequirement
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class GalaxyCLI(CLI):
diff --git a/lib/ansible/cli/inventory.py b/lib/ansible/cli/inventory.py
index a39148e707..a5dd98a446 100644
--- a/lib/ansible/cli/inventory.py
+++ b/lib/ansible/cli/inventory.py
@@ -27,12 +27,9 @@ from ansible.inventory.host import Host
from ansible.plugins.loader import vars_loader
from ansible.parsing.dataloader import DataLoader
from ansible.utils.vars import combine_vars
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
INTERNAL_VARS = frozenset(['ansible_diff_mode',
'ansible_facts',
diff --git a/lib/ansible/cli/playbook.py b/lib/ansible/cli/playbook.py
index 1cbf3e8087..8f3b40c17d 100644
--- a/lib/ansible/cli/playbook.py
+++ b/lib/ansible/cli/playbook.py
@@ -15,8 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
-########################################################
-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
@@ -28,12 +26,9 @@ from ansible.errors import AnsibleError, AnsibleOptionsError
from ansible.executor.playbook_executor import PlaybookExecutor
from ansible.playbook.block import Block
from ansible.playbook.play_context import PlayContext
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class PlaybookCLI(CLI):
diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py
index d6377ae9b0..44115611bc 100644
--- a/lib/ansible/cli/pull.py
+++ b/lib/ansible/cli/pull.py
@@ -18,7 +18,6 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
-########################################################
import datetime
import os
import platform
@@ -34,16 +33,11 @@ from ansible.errors import AnsibleOptionsError
from ansible.module_utils._text import to_native, to_text
from ansible.plugins.loader import module_loader
from ansible.utils.cmd_functions import run_cmd
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
-########################################################
-
class PullCLI(CLI):
''' is used to up a remote copy of ansible on each managed node,
each set to run via cron and update playbook source via a source repository.
diff --git a/lib/ansible/cli/vault.py b/lib/ansible/cli/vault.py
index dcc617765f..a5955e7132 100644
--- a/lib/ansible/cli/vault.py
+++ b/lib/ansible/cli/vault.py
@@ -28,12 +28,9 @@ from ansible.errors import AnsibleOptionsError
from ansible.module_utils._text import to_text, to_bytes
from ansible.parsing.dataloader import DataLoader
from ansible.parsing.vault import VaultEditor, VaultLib, match_encrypt_secret
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class VaultCLI(CLI):
diff --git a/lib/ansible/constants.py b/lib/ansible/constants.py
index fbe884f284..65892e01b9 100644
--- a/lib/ansible/constants.py
+++ b/lib/ansible/constants.py
@@ -20,8 +20,8 @@ from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_va
def _warning(msg):
''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
try:
- from __main__ import display
- display.warning(msg)
+ from ansible.utils.display import Display
+ Display().warning(msg)
except Exception:
import sys
sys.stderr.write(' [WARNING] %s\n' % (msg))
@@ -30,8 +30,8 @@ def _warning(msg):
def _deprecated(msg, version='2.8'):
''' display is not guaranteed here, nor it being the full class, but try anyways, fallback to sys.stderr.write '''
try:
- from __main__ import display
- display.deprecated(msg, version=version)
+ from ansible.utils.display import Display
+ Display().deprecated(msg, version=version)
except Exception:
import sys
sys.stderr.write(' [DEPRECATED] %s, to be removed in %s\n' % (msg, version))
diff --git a/lib/ansible/executor/module_common.py b/lib/ansible/executor/module_common.py
index f3f3006e94..65525ae3b4 100644
--- a/lib/ansible/executor/module_common.py
+++ b/lib/ansible/executor/module_common.py
@@ -42,12 +42,9 @@ from ansible.plugins.loader import module_utils_loader
# variable to the object and then it never gets updated.
from ansible.executor import action_write_locks
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
+display = Display()
REPLACER = b"#<<INCLUDE_ANSIBLE_MODULE_COMMON>>"
REPLACER_VERSION = b"\"<<ANSIBLE_VERSION>>\""
diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py
index 9bd78c932d..665e3fe181 100644
--- a/lib/ansible/executor/play_iterator.py
+++ b/lib/ansible/executor/play_iterator.py
@@ -26,13 +26,10 @@ from ansible.module_utils.six import iteritems
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.playbook.block import Block
from ansible.playbook.task import Task
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['PlayIterator']
diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py
index 4ad8214a4e..e23ad7957e 100644
--- a/lib/ansible/executor/playbook_executor.py
+++ b/lib/ansible/executor/playbook_executor.py
@@ -30,12 +30,9 @@ from ansible.utils.helpers import pct_to_int
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.utils.path import makedirs_safe
from ansible.utils.ssh_functions import check_for_controlpersist
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class PlaybookExecutor:
diff --git a/lib/ansible/executor/process/worker.py b/lib/ansible/executor/process/worker.py
index 2cf9bbb45a..a1296d2931 100644
--- a/lib/ansible/executor/process/worker.py
+++ b/lib/ansible/executor/process/worker.py
@@ -40,15 +40,12 @@ from ansible.errors import AnsibleConnectionFailure
from ansible.executor.task_executor import TaskExecutor
from ansible.executor.task_result import TaskResult
from ansible.module_utils._text import to_text
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
__all__ = ['WorkerProcess']
+display = Display()
+
class WorkerProcess(multiprocessing.Process):
'''
diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py
index 3d94531bb3..9ccb70f0f7 100644
--- a/lib/ansible/executor/task_executor.py
+++ b/lib/ansible/executor/task_executor.py
@@ -25,13 +25,10 @@ from ansible.template import Templar
from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.unsafe_proxy import UnsafeProxy, wrap_var
from ansible.vars.clean import namespace_facts, clean_facts
+from ansible.utils.display import Display
from ansible.utils.vars import combine_vars
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['TaskExecutor']
diff --git a/lib/ansible/executor/task_queue_manager.py b/lib/ansible/executor/task_queue_manager.py
index f45c5de4b3..67a741b989 100644
--- a/lib/ansible/executor/task_queue_manager.py
+++ b/lib/ansible/executor/task_queue_manager.py
@@ -38,16 +38,13 @@ from ansible.template import Templar
from ansible.utils.helpers import pct_to_int
from ansible.vars.hostvars import HostVars
from ansible.vars.reserved import warn_if_reserved
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
__all__ = ['TaskQueueManager']
+display = Display()
+
class TaskQueueManager:
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py
index 18bd031093..e11f3926ab 100644
--- a/lib/ansible/galaxy/api.py
+++ b/lib/ansible/galaxy/api.py
@@ -32,12 +32,9 @@ from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.six.moves.urllib.parse import quote as urlquote, urlencode
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.urls import open_url
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def g_connect(method):
diff --git a/lib/ansible/galaxy/login.py b/lib/ansible/galaxy/login.py
index 3b74aaa01c..e418a5ca60 100644
--- a/lib/ansible/galaxy/login.py
+++ b/lib/ansible/galaxy/login.py
@@ -31,12 +31,9 @@ from ansible.module_utils.six.moves.urllib.parse import quote as urlquote, urlpa
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.module_utils.urls import open_url
from ansible.utils.color import stringc
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class GalaxyLogin(object):
diff --git a/lib/ansible/galaxy/role.py b/lib/ansible/galaxy/role.py
index 9367486625..e727f112b0 100644
--- a/lib/ansible/galaxy/role.py
+++ b/lib/ansible/galaxy/role.py
@@ -36,12 +36,9 @@ from ansible.module_utils._text import to_native, to_text
from ansible.module_utils.urls import open_url
from ansible.playbook.role.requirement import RoleRequirement
from ansible.galaxy.api import GalaxyAPI
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class GalaxyRole(object):
diff --git a/lib/ansible/galaxy/token.py b/lib/ansible/galaxy/token.py
index edfeaee8dc..4af7511b4c 100644
--- a/lib/ansible/galaxy/token.py
+++ b/lib/ansible/galaxy/token.py
@@ -26,11 +26,9 @@ from stat import S_IRUSR, S_IWUSR
import yaml
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
+
+display = Display()
class GalaxyToken(object):
diff --git a/lib/ansible/inventory/data.py b/lib/ansible/inventory/data.py
index 9143c22410..e183845891 100644
--- a/lib/ansible/inventory/data.py
+++ b/lib/ansible/inventory/data.py
@@ -26,14 +26,11 @@ from ansible.errors import AnsibleError
from ansible.inventory.group import Group
from ansible.inventory.host import Host
from ansible.module_utils.six import iteritems, string_types
+from ansible.utils.display import Display
from ansible.utils.vars import combine_vars
from ansible.utils.path import basedir
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class InventoryData(object):
diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py
index 6e174a04f7..a920a5468a 100644
--- a/lib/ansible/inventory/manager.py
+++ b/lib/ansible/inventory/manager.py
@@ -32,12 +32,9 @@ from ansible.module_utils._text import to_bytes, to_text
from ansible.parsing.utils.addresses import parse_address
from ansible.plugins.loader import inventory_loader
from ansible.utils.path import unfrackpath
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
IGNORED_ALWAYS = [br"^\.", b"^host_vars$", b"^group_vars$", b"^vars_plugins$"]
IGNORED_PATTERNS = [to_bytes(x) for x in C.INVENTORY_IGNORE_PATTERNS]
diff --git a/lib/ansible/parsing/dataloader.py b/lib/ansible/parsing/dataloader.py
index 0b9a3ff9f2..390d0c2562 100644
--- a/lib/ansible/parsing/dataloader.py
+++ b/lib/ansible/parsing/dataloader.py
@@ -21,12 +21,9 @@ from ansible.parsing.quoting import unquote
from ansible.parsing.utils.yaml import from_yaml
from ansible.parsing.vault import VaultLib, b_HEADER, is_encrypted, is_encrypted_file, parse_vaulttext_envelope
from ansible.utils.path import unfrackpath
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# Tries to determine if a path is inside a role, last dir must be 'tasks'
diff --git a/lib/ansible/parsing/plugin_docs.py b/lib/ansible/parsing/plugin_docs.py
index 1f0dbbac17..d589fa9770 100644
--- a/lib/ansible/parsing/plugin_docs.py
+++ b/lib/ansible/parsing/plugin_docs.py
@@ -11,12 +11,9 @@ import yaml
from ansible.module_utils._text import to_text
from ansible.parsing.metadata import extract_metadata
from ansible.parsing.yaml.loader import AnsibleLoader
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def read_docstring(filename, verbose=True, ignore_errors=True):
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
index 851f509c64..b6967edde8 100644
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -75,13 +75,10 @@ from ansible.module_utils.six import PY3, binary_type
# Note: on py2, this zip is izip not the list based zip() builtin
from ansible.module_utils.six.moves import zip
from ansible.module_utils._text import to_bytes, to_text, to_native
+from ansible.utils.display import Display
from ansible.utils.path import makedirs_safe
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
b_HEADER = b'$ANSIBLE_VAULT'
diff --git a/lib/ansible/parsing/yaml/constructor.py b/lib/ansible/parsing/yaml/constructor.py
index 80f660a960..b6b4a3e7b8 100644
--- a/lib/ansible/parsing/yaml/constructor.py
+++ b/lib/ansible/parsing/yaml/constructor.py
@@ -27,12 +27,9 @@ from ansible.parsing.yaml.objects import AnsibleMapping, AnsibleSequence, Ansibl
from ansible.parsing.yaml.objects import AnsibleVaultEncryptedUnicode
from ansible.utils.unsafe_proxy import wrap_var
from ansible.parsing.vault import VaultLib
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class AnsibleConstructor(SafeConstructor):
diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py
index 6c07250721..9237478ddf 100644
--- a/lib/ansible/playbook/__init__.py
+++ b/lib/ansible/playbook/__init__.py
@@ -27,12 +27,9 @@ from ansible.module_utils._text import to_text, to_native
from ansible.playbook.play import Play
from ansible.playbook.playbook_include import PlaybookInclude
from ansible.plugins.loader import get_all_plugin_loaders
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['Playbook']
diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py
index 48343050dd..e74bfbd557 100644
--- a/lib/ansible/playbook/base.py
+++ b/lib/ansible/playbook/base.py
@@ -21,12 +21,9 @@ from ansible.module_utils._text import to_text, to_native
from ansible.playbook.attribute import Attribute, FieldAttribute
from ansible.parsing.dataloader import DataLoader
from ansible.utils.vars import combine_vars, isidentifier, get_unique_id
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def _generic_g(prop_name, self):
diff --git a/lib/ansible/playbook/become.py b/lib/ansible/playbook/become.py
index 8f607176ad..374411cb14 100644
--- a/lib/ansible/playbook/become.py
+++ b/lib/ansible/playbook/become.py
@@ -22,12 +22,9 @@ __metaclass__ = type
from ansible import constants as C
from ansible.errors import AnsibleParserError
from ansible.playbook.attribute import FieldAttribute
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Become:
diff --git a/lib/ansible/playbook/conditional.py b/lib/ansible/playbook/conditional.py
index 0e846240dc..3f86368d42 100644
--- a/lib/ansible/playbook/conditional.py
+++ b/lib/ansible/playbook/conditional.py
@@ -29,13 +29,9 @@ from ansible.errors import AnsibleError, AnsibleUndefinedVariable
from ansible.module_utils.six import text_type
from ansible.module_utils._text import to_native
from ansible.playbook.attribute import FieldAttribute
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
+display = Display()
DEFINED_REGEX = re.compile(r'(hostvars\[.+\]|[\w_]+)\s+(not\s+is|is|is\s+not)\s+(defined|undefined)')
LOOKUP_REGEX = re.compile(r'lookup\s*\(')
diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py
index 2196ff42dd..dd49713b08 100644
--- a/lib/ansible/playbook/helpers.py
+++ b/lib/ansible/playbook/helpers.py
@@ -25,12 +25,9 @@ from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, Ansible
from ansible.module_utils._text import to_native
from ansible.module_utils.six import string_types
from ansible.parsing.mod_args import ModuleArgsParser
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def load_list_of_blocks(ds, play, parent_block=None, role=None, task_include=None, use_handlers=False, variable_manager=None, loader=None):
diff --git a/lib/ansible/playbook/included_file.py b/lib/ansible/playbook/included_file.py
index 1a6a519fc7..51649812de 100644
--- a/lib/ansible/playbook/included_file.py
+++ b/lib/ansible/playbook/included_file.py
@@ -24,12 +24,9 @@ import os
from ansible.playbook.task_include import TaskInclude
from ansible.playbook.role_include import IncludeRole
from ansible.template import Templar
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class IncludedFile:
diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py
index 2469122ca1..6dbd384d38 100644
--- a/lib/ansible/playbook/play.py
+++ b/lib/ansible/playbook/play.py
@@ -30,12 +30,9 @@ from ansible.playbook.helpers import load_list_of_blocks, load_list_of_roles
from ansible.playbook.role import Role
from ansible.playbook.taggable import Taggable
from ansible.vars.manager import preprocess_vars
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['Play']
diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py
index d1ec159bb9..de3a702250 100644
--- a/lib/ansible/playbook/play_context.py
+++ b/lib/ansible/playbook/play_context.py
@@ -37,14 +37,11 @@ from ansible.module_utils.parsing.convert_bool import boolean
from ansible.playbook.attribute import FieldAttribute
from ansible.playbook.base import Base
from ansible.plugins import get_plugin_class
+from ansible.utils.display import Display
from ansible.utils.ssh_functions import check_for_controlpersist
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['PlayContext']
diff --git a/lib/ansible/playbook/role/definition.py b/lib/ansible/playbook/role/definition.py
index 658749c271..235a54490e 100644
--- a/lib/ansible/playbook/role/definition.py
+++ b/lib/ansible/playbook/role/definition.py
@@ -32,16 +32,12 @@ from ansible.playbook.conditional import Conditional
from ansible.playbook.taggable import Taggable
from ansible.template import Templar
from ansible.utils.path import unfrackpath
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
+from ansible.utils.display import Display
__all__ = ['RoleDefinition']
+display = Display()
+
class RoleDefinition(Base, Become, Conditional, Taggable):
diff --git a/lib/ansible/playbook/role/requirement.py b/lib/ansible/playbook/role/requirement.py
index 764d0c591f..d77dda6991 100644
--- a/lib/ansible/playbook/role/requirement.py
+++ b/lib/ansible/playbook/role/requirement.py
@@ -31,11 +31,10 @@ from ansible.module_utils._text import to_native
from ansible.module_utils.common.process import get_bin_path
from ansible.module_utils.six import string_types
from ansible.playbook.role.definition import RoleDefinition
-
+from ansible.utils.display import Display
__all__ = ['RoleRequirement']
-
VALID_SPEC_KEYS = [
'name',
'role',
@@ -44,11 +43,7 @@ VALID_SPEC_KEYS = [
'version',
]
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class RoleRequirement(RoleDefinition):
diff --git a/lib/ansible/playbook/role_include.py b/lib/ansible/playbook/role_include.py
index bfabca4b55..c84342a2fc 100644
--- a/lib/ansible/playbook/role_include.py
+++ b/lib/ansible/playbook/role_include.py
@@ -1,4 +1,3 @@
-
#
# This file is part of Ansible
#
@@ -27,15 +26,12 @@ from ansible.playbook.block import Block
from ansible.playbook.task_include import TaskInclude
from ansible.playbook.role import Role
from ansible.playbook.role.include import RoleInclude
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
__all__ = ['IncludeRole']
+display = Display()
+
class IncludeRole(TaskInclude):
diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py
index 72ec21c25f..34cd15568f 100644
--- a/lib/ansible/playbook/task.py
+++ b/lib/ansible/playbook/task.py
@@ -36,16 +36,12 @@ from ansible.playbook.conditional import Conditional
from ansible.playbook.loop_control import LoopControl
from ansible.playbook.role import Role
from ansible.playbook.taggable import Taggable
-
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
__all__ = ['Task']
+display = Display()
+
class Task(Base, Conditional, Taggable, Become):
diff --git a/lib/ansible/playbook/task_include.py b/lib/ansible/playbook/task_include.py
index 40b7861cd7..5a11f4c635 100644
--- a/lib/ansible/playbook/task_include.py
+++ b/lib/ansible/playbook/task_include.py
@@ -24,15 +24,12 @@ from ansible.errors import AnsibleParserError
from ansible.playbook.attribute import FieldAttribute
from ansible.playbook.block import Block
from ansible.playbook.task import Task
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
__all__ = ['TaskInclude']
+display = Display()
+
class TaskInclude(Task):
diff --git a/lib/ansible/plugins/__init__.py b/lib/ansible/plugins/__init__.py
index 87c7ba446d..a788222936 100644
--- a/lib/ansible/plugins/__init__.py
+++ b/lib/ansible/plugins/__init__.py
@@ -25,12 +25,9 @@ from abc import ABCMeta
from ansible import constants as C
from ansible.module_utils.six import with_metaclass, string_types
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# Global so that all instances of a PluginLoader will share the caches
MODULE_CACHE = {}
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index ada3b6ba9f..63ef5b906a 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -26,15 +26,12 @@ from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.parsing.utils.jsonify import jsonify
from ansible.release import __version__
+from ansible.utils.display import Display
from ansible.utils.unsafe_proxy import wrap_var
from ansible.vars.clean import remove_internal_keys
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionBase(with_metaclass(ABCMeta, object)):
diff --git a/lib/ansible/plugins/action/add_host.py b/lib/ansible/plugins/action/add_host.py
index f92588fe7d..5851994fdb 100644
--- a/lib/ansible/plugins/action/add_host.py
+++ b/lib/ansible/plugins/action/add_host.py
@@ -24,12 +24,9 @@ from ansible.errors import AnsibleError
from ansible.module_utils.six import string_types
from ansible.plugins.action import ActionBase
from ansible.parsing.utils.addresses import parse_address
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/aireos.py b/lib/ansible/plugins/action/aireos.py
index d9c61242a9..18bcad695c 100644
--- a/lib/ansible/plugins/action/aireos.py
+++ b/lib/ansible/plugins/action/aireos.py
@@ -28,13 +28,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.aireos.aireos import aireos_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/aruba.py b/lib/ansible/plugins/action/aruba.py
index c573938cd2..daf4e64efc 100644
--- a/lib/ansible/plugins/action/aruba.py
+++ b/lib/ansible/plugins/action/aruba.py
@@ -28,12 +28,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.aruba.aruba import aruba_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/asa.py b/lib/ansible/plugins/action/asa.py
index eec4750a29..1406b6dc88 100644
--- a/lib/ansible/plugins/action/asa.py
+++ b/lib/ansible/plugins/action/asa.py
@@ -27,13 +27,9 @@ from ansible import constants as C
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.asa.asa import asa_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/bigip.py b/lib/ansible/plugins/action/bigip.py
index 967f6074b4..9d89b4d3b8 100644
--- a/lib/ansible/plugins/action/bigip.py
+++ b/lib/ansible/plugins/action/bigip.py
@@ -28,17 +28,14 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.connection import Connection
from ansible.module_utils.network.common.utils import load_provider
from ansible.plugins.action.normal import ActionModule as _ActionModule
+from ansible.utils.display import Display
try:
from library.module_utils.network.f5.common import f5_provider_spec
except:
from ansible.module_utils.network.f5.common import f5_provider_spec
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/bigiq.py b/lib/ansible/plugins/action/bigiq.py
index 182d917cb2..95ed9252a4 100644
--- a/lib/ansible/plugins/action/bigiq.py
+++ b/lib/ansible/plugins/action/bigiq.py
@@ -28,17 +28,14 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.connection import Connection
from ansible.module_utils.network.common.utils import load_provider
from ansible.plugins.action.normal import ActionModule as _ActionModule
+from ansible.utils.display import Display
try:
from library.module_utils.network.f5.common import f5_provider_spec
except:
from ansible.module_utils.network.f5.common import f5_provider_spec
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/ce.py b/lib/ansible/plugins/action/ce.py
index 2211083a1a..fa5653bc61 100644
--- a/lib/ansible/plugins/action/ce.py
+++ b/lib/ansible/plugins/action/ce.py
@@ -28,13 +28,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.cloudengine.ce import ce_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
CLI_SUPPORTED_MODULES = ['ce_config', 'ce_command']
diff --git a/lib/ansible/plugins/action/cnos.py b/lib/ansible/plugins/action/cnos.py
index d2f6a3b0a7..0c62124082 100644
--- a/lib/ansible/plugins/action/cnos.py
+++ b/lib/ansible/plugins/action/cnos.py
@@ -26,13 +26,9 @@ from ansible.module_utils.network.cnos.cnos import cnos_provider_spec
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.connection import Connection
from ansible.module_utils._text import to_text
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/dellos10.py b/lib/ansible/plugins/action/dellos10.py
index f3eab92db0..b102f884ee 100644
--- a/lib/ansible/plugins/action/dellos10.py
+++ b/lib/ansible/plugins/action/dellos10.py
@@ -30,12 +30,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.dellos10.dellos10 import dellos10_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/dellos6.py b/lib/ansible/plugins/action/dellos6.py
index c505789456..84049f14bc 100644
--- a/lib/ansible/plugins/action/dellos6.py
+++ b/lib/ansible/plugins/action/dellos6.py
@@ -30,12 +30,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.dellos6.dellos6 import dellos6_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/dellos9.py b/lib/ansible/plugins/action/dellos9.py
index df13626c75..202061b1df 100644
--- a/lib/ansible/plugins/action/dellos9.py
+++ b/lib/ansible/plugins/action/dellos9.py
@@ -30,12 +30,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.dellos9.dellos9 import dellos9_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/enos.py b/lib/ansible/plugins/action/enos.py
index 1182f57e58..58bd4ca390 100644
--- a/lib/ansible/plugins/action/enos.py
+++ b/lib/ansible/plugins/action/enos.py
@@ -26,13 +26,9 @@ from ansible.module_utils.network.enos.enos import enos_provider_spec
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.connection import Connection
from ansible.module_utils._text import to_text
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/eos.py b/lib/ansible/plugins/action/eos.py
index 0ecfcb7622..218e53d080 100644
--- a/lib/ansible/plugins/action/eos.py
+++ b/lib/ansible/plugins/action/eos.py
@@ -28,12 +28,9 @@ from ansible.module_utils.connection import Connection
from ansible.module_utils.network.eos.eos import eos_provider_spec
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/fetch.py b/lib/ansible/plugins/action/fetch.py
index 8d2c59f31e..515dd0177a 100644
--- a/lib/ansible/plugins/action/fetch.py
+++ b/lib/ansible/plugins/action/fetch.py
@@ -25,14 +25,11 @@ from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import string_types
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
from ansible.utils.hashing import checksum, checksum_s, md5, secure_hash
from ansible.utils.path import makedirs_safe
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/ios.py b/lib/ansible/plugins/action/ios.py
index f2ad0de7d9..612d27189a 100644
--- a/lib/ansible/plugins/action/ios.py
+++ b/lib/ansible/plugins/action/ios.py
@@ -28,12 +28,9 @@ from ansible.module_utils.connection import Connection, ConnectionError
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.ios.ios import ios_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/iosxr.py b/lib/ansible/plugins/action/iosxr.py
index 2a7b6db3ae..dac0168f3e 100644
--- a/lib/ansible/plugins/action/iosxr.py
+++ b/lib/ansible/plugins/action/iosxr.py
@@ -28,12 +28,9 @@ from ansible.module_utils.connection import Connection
from ansible.module_utils.network.iosxr.iosxr import iosxr_provider_spec
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/ironware.py b/lib/ansible/plugins/action/ironware.py
index b84df72ff6..b1a77b072c 100644
--- a/lib/ansible/plugins/action/ironware.py
+++ b/lib/ansible/plugins/action/ironware.py
@@ -28,12 +28,9 @@ from ansible.module_utils.connection import Connection, ConnectionError
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.ironware.ironware import ironware_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/junos.py b/lib/ansible/plugins/action/junos.py
index 32bca0f84c..e925c9db14 100644
--- a/lib/ansible/plugins/action/junos.py
+++ b/lib/ansible/plugins/action/junos.py
@@ -29,13 +29,9 @@ from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.junos.junos import junos_provider_spec
from ansible.plugins.loader import connection_loader, module_loader
from ansible.plugins.action.normal import ActionModule as _ActionModule
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
CLI_SUPPORTED_MODULES = ['junos_netconf', 'junos_command']
diff --git a/lib/ansible/plugins/action/net_base.py b/lib/ansible/plugins/action/net_base.py
index b4f75b7f42..be8f8d438e 100644
--- a/lib/ansible/plugins/action/net_base.py
+++ b/lib/ansible/plugins/action/net_base.py
@@ -28,14 +28,11 @@ from ansible.plugins.action import ActionBase
from ansible.plugins.action.nxos import ActionModule as _NxosActionModule
from ansible.plugins.action.eos import ActionModule as _EosActionModule
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
from imp import find_module, load_module
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
_CLI_ONLY_MODULES = frozenset(['junos_netconf', 'iosxr_netconf', 'iosxr_config', 'iosxr_command'])
_NETCONF_SUPPORTED_PLATFORMS = frozenset(['junos', 'iosxr'])
diff --git a/lib/ansible/plugins/action/net_get.py b/lib/ansible/plugins/action/net_get.py
index 19d2da534c..f5f4797213 100644
--- a/lib/ansible/plugins/action/net_get.py
+++ b/lib/ansible/plugins/action/net_get.py
@@ -29,12 +29,9 @@ from ansible.module_utils.connection import Connection
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase
from ansible.module_utils.six.moves.urllib.parse import urlsplit
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/net_put.py b/lib/ansible/plugins/action/net_put.py
index d71bcbfd3a..993d81270a 100644
--- a/lib/ansible/plugins/action/net_put.py
+++ b/lib/ansible/plugins/action/net_put.py
@@ -30,12 +30,9 @@ from ansible.module_utils.connection import Connection
from ansible.errors import AnsibleError
from ansible.plugins.action import ActionBase
from ansible.module_utils.six.moves.urllib.parse import urlsplit
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/netconf.py b/lib/ansible/plugins/action/netconf.py
index 27d2cc84c7..73b0cbf334 100644
--- a/lib/ansible/plugins/action/netconf.py
+++ b/lib/ansible/plugins/action/netconf.py
@@ -23,12 +23,9 @@ import copy
import sys
from ansible.plugins.action.normal import ActionModule as _ActionModule
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/nxos.py b/lib/ansible/plugins/action/nxos.py
index 656d49178f..d62391f80f 100644
--- a/lib/ansible/plugins/action/nxos.py
+++ b/lib/ansible/plugins/action/nxos.py
@@ -29,12 +29,9 @@ from ansible.module_utils.connection import Connection
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.nxos.nxos import nxos_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/package.py b/lib/ansible/plugins/action/package.py
index 964d077eab..75a8dd5628 100644
--- a/lib/ansible/plugins/action/package.py
+++ b/lib/ansible/plugins/action/package.py
@@ -19,12 +19,9 @@ __metaclass__ = type
from ansible.errors import AnsibleAction, AnsibleActionFail
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py
index a347ad9ddf..3a965a875e 100644
--- a/lib/ansible/plugins/action/pause.py
+++ b/lib/ansible/plugins/action/pause.py
@@ -30,12 +30,9 @@ from ansible.module_utils._text import to_text, to_native
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import PY3
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
try:
import curses
diff --git a/lib/ansible/plugins/action/reboot.py b/lib/ansible/plugins/action/reboot.py
index b62e2451e1..f09d51318e 100644
--- a/lib/ansible/plugins/action/reboot.py
+++ b/lib/ansible/plugins/action/reboot.py
@@ -13,13 +13,9 @@ from datetime import datetime, timedelta
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.module_utils._text import to_native, to_text
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class TimedOutException(Exception):
diff --git a/lib/ansible/plugins/action/sros.py b/lib/ansible/plugins/action/sros.py
index 5a3cb9a527..47682eb86a 100644
--- a/lib/ansible/plugins/action/sros.py
+++ b/lib/ansible/plugins/action/sros.py
@@ -26,12 +26,9 @@ from ansible import constants as C
from ansible.plugins.action.normal import ActionModule as _ActionModule
from ansible.module_utils.network.sros.sros import sros_provider_spec
from ansible.module_utils.network.common.utils import load_provider
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/telnet.py b/lib/ansible/plugins/action/telnet.py
index 63b3870c34..785681e0a2 100644
--- a/lib/ansible/plugins/action/telnet.py
+++ b/lib/ansible/plugins/action/telnet.py
@@ -11,12 +11,9 @@ from time import sleep
from ansible.module_utils._text import to_native, to_bytes
from ansible.module_utils.six import text_type
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/vyos.py b/lib/ansible/plugins/action/vyos.py
index c4d8b3bbe5..624a1259df 100644
--- a/lib/ansible/plugins/action/vyos.py
+++ b/lib/ansible/plugins/action/vyos.py
@@ -28,12 +28,9 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.connection import Connection
from ansible.module_utils.network.common.utils import load_provider
from ansible.module_utils.network.vyos.vyos import vyos_provider_spec
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(_ActionModule):
diff --git a/lib/ansible/plugins/action/wait_for_connection.py b/lib/ansible/plugins/action/wait_for_connection.py
index 93643c7756..7810052cea 100644
--- a/lib/ansible/plugins/action/wait_for_connection.py
+++ b/lib/ansible/plugins/action/wait_for_connection.py
@@ -24,12 +24,9 @@ from datetime import datetime, timedelta
from ansible.module_utils._text import to_text
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class TimedOutException(Exception):
diff --git a/lib/ansible/plugins/action/win_reboot.py b/lib/ansible/plugins/action/win_reboot.py
index e0189849f1..1e61668a7e 100644
--- a/lib/ansible/plugins/action/win_reboot.py
+++ b/lib/ansible/plugins/action/win_reboot.py
@@ -10,12 +10,9 @@ from ansible.errors import AnsibleError
from ansible.module_utils._text import to_native
from ansible.plugins.action import ActionBase
from ansible.plugins.action.reboot import ActionModule as RebootActionModule
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class TimedOutException(Exception):
diff --git a/lib/ansible/plugins/action/win_updates.py b/lib/ansible/plugins/action/win_updates.py
index 70f22629cc..538af250a3 100644
--- a/lib/ansible/plugins/action/win_updates.py
+++ b/lib/ansible/plugins/action/win_updates.py
@@ -8,12 +8,9 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.parsing.yaml.objects import AnsibleUnicode
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/action/yum.py b/lib/ansible/plugins/action/yum.py
index a05aa6cbd0..468321a429 100644
--- a/lib/ansible/plugins/action/yum.py
+++ b/lib/ansible/plugins/action/yum.py
@@ -18,12 +18,9 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.action import ActionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class ActionModule(ActionBase):
diff --git a/lib/ansible/plugins/cache/__init__.py b/lib/ansible/plugins/cache/__init__.py
index ef1d9d5013..2b1d51fb5a 100644
--- a/lib/ansible/plugins/cache/__init__.py
+++ b/lib/ansible/plugins/cache/__init__.py
@@ -28,12 +28,9 @@ from ansible.module_utils.six import with_metaclass
from ansible.module_utils._text import to_bytes
from ansible.module_utils.common._collections_compat import MutableMapping
from ansible.plugins.loader import cache_loader
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class BaseCacheModule(with_metaclass(ABCMeta, object)):
diff --git a/lib/ansible/plugins/callback/__init__.py b/lib/ansible/plugins/callback/__init__.py
index 88c864a0ae..42c03fda9f 100644
--- a/lib/ansible/plugins/callback/__init__.py
+++ b/lib/ansible/plugins/callback/__init__.py
@@ -32,13 +32,10 @@ from ansible.module_utils.common._collections_compat import MutableMapping
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.plugins import AnsiblePlugin, get_plugin_class
from ansible.utils.color import stringc
+from ansible.utils.display import Display
from ansible.vars.clean import strip_internal_keys
-try:
- from __main__ import display as global_display
-except ImportError:
- from ansible.utils.display import Display
- global_display = Display()
+global_display = Display()
try:
from __main__ import cli
diff --git a/lib/ansible/plugins/callback/dense.py b/lib/ansible/plugins/callback/dense.py
index b442cfcd0b..86a7595b48 100644
--- a/lib/ansible/plugins/callback/dense.py
+++ b/lib/ansible/plugins/callback/dense.py
@@ -31,15 +31,13 @@ from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSequence
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
from ansible.utils.color import colorize, hostcolor
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
import sys
+display = Display()
+
+
# Design goals:
#
# + On screen there should only be relevant stuff
diff --git a/lib/ansible/plugins/cliconf/__init__.py b/lib/ansible/plugins/cliconf/__init__.py
index acf4b26ae3..4cf823b145 100644
--- a/lib/ansible/plugins/cliconf/__init__.py
+++ b/lib/ansible/plugins/cliconf/__init__.py
@@ -25,7 +25,7 @@ from functools import wraps
from ansible.plugins import AnsiblePlugin
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes, to_text
-
+from ansible.utils.display import Display
try:
from scp import SCPClient
@@ -33,11 +33,7 @@ try:
except ImportError:
HAS_SCP = False
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def enable_mode(func):
diff --git a/lib/ansible/plugins/cliconf/routeros.py b/lib/ansible/plugins/cliconf/routeros.py
index d0d77a31b9..902bea1b2e 100644
--- a/lib/ansible/plugins/cliconf/routeros.py
+++ b/lib/ansible/plugins/cliconf/routeros.py
@@ -27,12 +27,9 @@ from itertools import chain
from ansible.module_utils._text import to_bytes, to_text
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.cliconf import CliconfBase, enable_mode
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Cliconf(CliconfBase):
diff --git a/lib/ansible/plugins/connection/__init__.py b/lib/ansible/plugins/connection/__init__.py
index 4d4e3d5eca..43409f4b7a 100644
--- a/lib/ansible/plugins/connection/__init__.py
+++ b/lib/ansible/plugins/connection/__init__.py
@@ -18,13 +18,10 @@ from ansible.module_utils.six import string_types
from ansible.module_utils._text import to_bytes, to_text
from ansible.plugins import AnsiblePlugin
from ansible.plugins.loader import shell_loader, connection_loader
+from ansible.utils.display import Display
from ansible.utils.path import unfrackpath
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['ConnectionBase', 'ensure_connect']
diff --git a/lib/ansible/plugins/connection/buildah.py b/lib/ansible/plugins/connection/buildah.py
index 37d0326a12..c4e2c73f0f 100644
--- a/lib/ansible/plugins/connection/buildah.py
+++ b/lib/ansible/plugins/connection/buildah.py
@@ -49,13 +49,9 @@ import subprocess
import ansible.constants as C
from ansible.module_utils._text import to_bytes, to_native
from ansible.plugins.connection import ConnectionBase, ensure_connect
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# this _has to be_ named Connection
diff --git a/lib/ansible/plugins/connection/chroot.py b/lib/ansible/plugins/connection/chroot.py
index faaf691040..78af1c59e8 100644
--- a/lib/ansible/plugins/connection/chroot.py
+++ b/lib/ansible/plugins/connection/chroot.py
@@ -46,13 +46,9 @@ from ansible.module_utils.basic import is_executable
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/docker.py b/lib/ansible/plugins/connection/docker.py
index 76859a7183..68869e0ae1 100644
--- a/lib/ansible/plugins/connection/docker.py
+++ b/lib/ansible/plugins/connection/docker.py
@@ -52,13 +52,9 @@ from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/funcd.py b/lib/ansible/plugins/connection/funcd.py
index 5401725b69..7bd957550e 100644
--- a/lib/ansible/plugins/connection/funcd.py
+++ b/lib/ansible/plugins/connection/funcd.py
@@ -38,12 +38,9 @@ import tempfile
import shutil
from ansible.errors import AnsibleError
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(object):
diff --git a/lib/ansible/plugins/connection/httpapi.py b/lib/ansible/plugins/connection/httpapi.py
index cd5bf324dc..e44e1608ca 100644
--- a/lib/ansible/plugins/connection/httpapi.py
+++ b/lib/ansible/plugins/connection/httpapi.py
@@ -156,12 +156,9 @@ from ansible.module_utils.urls import open_url
from ansible.playbook.play_context import PlayContext
from ansible.plugins.loader import cliconf_loader, httpapi_loader
from ansible.plugins.connection import NetworkConnectionBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(NetworkConnectionBase):
diff --git a/lib/ansible/plugins/connection/iocage.py b/lib/ansible/plugins/connection/iocage.py
index b1f01c4435..a7bd85d4ff 100644
--- a/lib/ansible/plugins/connection/iocage.py
+++ b/lib/ansible/plugins/connection/iocage.py
@@ -35,12 +35,9 @@ import subprocess
from ansible.plugins.connection.jail import Connection as Jail
from ansible.errors import AnsibleError
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(Jail):
diff --git a/lib/ansible/plugins/connection/jail.py b/lib/ansible/plugins/connection/jail.py
index 8d9018ae93..f8fb5d277f 100644
--- a/lib/ansible/plugins/connection/jail.py
+++ b/lib/ansible/plugins/connection/jail.py
@@ -42,12 +42,9 @@ from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/kubectl.py b/lib/ansible/plugins/connection/kubectl.py
index 063d38d437..6094051b6f 100644
--- a/lib/ansible/plugins/connection/kubectl.py
+++ b/lib/ansible/plugins/connection/kubectl.py
@@ -167,13 +167,9 @@ from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
CONNECTION_TRANSPORT = 'kubectl'
diff --git a/lib/ansible/plugins/connection/libvirt_lxc.py b/lib/ansible/plugins/connection/libvirt_lxc.py
index 10057b9cec..fe37905365 100644
--- a/lib/ansible/plugins/connection/libvirt_lxc.py
+++ b/lib/ansible/plugins/connection/libvirt_lxc.py
@@ -36,13 +36,9 @@ from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/local.py b/lib/ansible/plugins/connection/local.py
index e4ea3f5ac0..0ed9d820cb 100644
--- a/lib/ansible/plugins/connection/local.py
+++ b/lib/ansible/plugins/connection/local.py
@@ -28,13 +28,9 @@ from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.module_utils.six import text_type, binary_type
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/napalm.py b/lib/ansible/plugins/connection/napalm.py
index 242fb00403..e2f1a913fc 100644
--- a/lib/ansible/plugins/connection/napalm.py
+++ b/lib/ansible/plugins/connection/napalm.py
@@ -131,6 +131,7 @@ options:
from ansible.errors import AnsibleConnectionFailure, AnsibleError
from ansible.plugins.connection import NetworkConnectionBase
+from ansible.utils.display import Display
try:
from napalm import get_network_driver
@@ -142,11 +143,7 @@ except ImportError:
'Please run pip install napalm'
)
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(NetworkConnectionBase):
diff --git a/lib/ansible/plugins/connection/netconf.py b/lib/ansible/plugins/connection/netconf.py
index 1466db905c..8ac51a990b 100644
--- a/lib/ansible/plugins/connection/netconf.py
+++ b/lib/ansible/plugins/connection/netconf.py
@@ -181,6 +181,7 @@ from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE
from ansible.plugins.loader import netconf_loader
from ansible.plugins.connection import NetworkConnectionBase
+from ansible.utils.display import Display
try:
from ncclient import manager
@@ -190,11 +191,7 @@ try:
except ImportError:
raise AnsibleError("ncclient is not installed")
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
logging.getLogger('ncclient').setLevel(logging.INFO)
diff --git a/lib/ansible/plugins/connection/network_cli.py b/lib/ansible/plugins/connection/network_cli.py
index 18dbd25104..63e68032c3 100644
--- a/lib/ansible/plugins/connection/network_cli.py
+++ b/lib/ansible/plugins/connection/network_cli.py
@@ -192,12 +192,9 @@ from ansible.module_utils._text import to_bytes, to_text
from ansible.playbook.play_context import PlayContext
from ansible.plugins.connection import NetworkConnectionBase
from ansible.plugins.loader import cliconf_loader, terminal_loader, connection_loader
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class AnsibleCmdRespRecv(Exception):
diff --git a/lib/ansible/plugins/connection/paramiko_ssh.py b/lib/ansible/plugins/connection/paramiko_ssh.py
index c12b6f1025..b15d2cf78e 100644
--- a/lib/ansible/plugins/connection/paramiko_ssh.py
+++ b/lib/ansible/plugins/connection/paramiko_ssh.py
@@ -144,14 +144,11 @@ from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNo
from ansible.module_utils.six import iteritems
from ansible.module_utils.six.moves import input
from ansible.plugins.connection import ConnectionBase
+from ansible.utils.display import Display
from ansible.utils.path import makedirs_safe
from ansible.module_utils._text import to_bytes, to_native, to_text
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
AUTHENTICITY_MSG = """
diff --git a/lib/ansible/plugins/connection/persistent.py b/lib/ansible/plugins/connection/persistent.py
index f77a23bf1c..943c470003 100644
--- a/lib/ansible/plugins/connection/persistent.py
+++ b/lib/ansible/plugins/connection/persistent.py
@@ -41,12 +41,9 @@ from ansible.plugins.connection import ConnectionBase
from ansible.module_utils._text import to_text
from ansible.module_utils.connection import Connection as SocketConnection, write_to_file_descriptor
from ansible.errors import AnsibleError
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/podman.py b/lib/ansible/plugins/connection/podman.py
index cc342a3994..26e53c2278 100644
--- a/lib/ansible/plugins/connection/podman.py
+++ b/lib/ansible/plugins/connection/podman.py
@@ -16,13 +16,9 @@ import subprocess
from ansible.module_utils._text import to_bytes, to_native
from ansible.plugins.connection import ConnectionBase, ensure_connect
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
DOCUMENTATION = """
diff --git a/lib/ansible/plugins/connection/psrp.py b/lib/ansible/plugins/connection/psrp.py
index 6a36f92d76..459d45fc21 100644
--- a/lib/ansible/plugins/connection/psrp.py
+++ b/lib/ansible/plugins/connection/psrp.py
@@ -164,6 +164,7 @@ from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.plugins.connection import ConnectionBase
from ansible.plugins.shell.powershell import _common_args
+from ansible.utils.display import Display
from ansible.utils.hashing import secure_hash
from ansible.utils.path import makedirs_safe
@@ -181,11 +182,7 @@ except ImportError as err:
HAS_PYPSRP = False
PYPSRP_IMP_ERR = err
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/qubes.py b/lib/ansible/plugins/connection/qubes.py
index 7faa9510d2..240cb1d651 100644
--- a/lib/ansible/plugins/connection/qubes.py
+++ b/lib/ansible/plugins/connection/qubes.py
@@ -49,13 +49,9 @@ import ansible.constants as C
from ansible.module_utils._text import to_bytes, to_native
from ansible.plugins.connection import ConnectionBase, ensure_connect
from ansible.errors import AnsibleConnectionFailure
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# this _has to be_ named Connection
diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py
index 67187386d5..8f5f2933c7 100644
--- a/lib/ansible/plugins/connection/ssh.py
+++ b/lib/ansible/plugins/connection/ssh.py
@@ -288,13 +288,10 @@ from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.module_utils.parsing.convert_bool import BOOLEANS, boolean
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
from ansible.utils.path import unfrackpath, makedirs_safe
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
b_NOT_SSH_ERRORS = (b'Traceback (most recent call last):', # Python-2.6 when there's an exception
diff --git a/lib/ansible/plugins/connection/winrm.py b/lib/ansible/plugins/connection/winrm.py
index e316f8ecb5..325665ac42 100644
--- a/lib/ansible/plugins/connection/winrm.py
+++ b/lib/ansible/plugins/connection/winrm.py
@@ -120,6 +120,7 @@ from ansible.module_utils.six import binary_type, PY3
from ansible.plugins.connection import ConnectionBase
from ansible.utils.hashing import secure_hash
from ansible.utils.path import makedirs_safe
+from ansible.utils.display import Display
# getargspec is deprecated in favour of getfullargspec in Python 3 but
# getfullargspec is not available in Python 2
@@ -164,11 +165,7 @@ try:
except ImportError:
HAS_IPADDRESS = False
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/connection/zone.py b/lib/ansible/plugins/connection/zone.py
index 15ed4417a9..ce39427ed8 100644
--- a/lib/ansible/plugins/connection/zone.py
+++ b/lib/ansible/plugins/connection/zone.py
@@ -37,13 +37,9 @@ from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import shlex_quote
from ansible.module_utils._text import to_bytes
from ansible.plugins.connection import ConnectionBase, BUFSIZE
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Connection(ConnectionBase):
diff --git a/lib/ansible/plugins/filter/core.py b/lib/ansible/plugins/filter/core.py
index d2ad516e25..b9072900f6 100644
--- a/lib/ansible/plugins/filter/core.py
+++ b/lib/ansible/plugins/filter/core.py
@@ -48,16 +48,13 @@ from ansible.module_utils.common.collections import is_sequence
from ansible.module_utils.common._collections_compat import MutableMapping
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.parsing.yaml.dumper import AnsibleDumper
+from ansible.utils.display import Display
from ansible.utils.encrypt import passlib_or_crypt
from ansible.utils.hashing import md5s, checksum_s
from ansible.utils.unicode import unicode_wrap
from ansible.utils.vars import merge_hash
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
UUID_NAMESPACE_ANSIBLE = uuid.UUID('361E6D51-FAEC-444A-9079-341386DA8E2E')
diff --git a/lib/ansible/plugins/filter/mathstuff.py b/lib/ansible/plugins/filter/mathstuff.py
index 67f628388f..71cd85ad9c 100644
--- a/lib/ansible/plugins/filter/mathstuff.py
+++ b/lib/ansible/plugins/filter/mathstuff.py
@@ -34,6 +34,7 @@ from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils.six.moves import zip, zip_longest
from ansible.module_utils.common._collections_compat import Hashable, Mapping, Iterable
from ansible.module_utils._text import to_native, to_text
+from ansible.utils.display import Display
try:
from jinja2.filters import do_unique
@@ -41,11 +42,7 @@ try:
except ImportError:
HAS_UNIQUE = False
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
@environmentfilter
diff --git a/lib/ansible/plugins/filter/network.py b/lib/ansible/plugins/filter/network.py
index 92d0230777..ffa8e664af 100644
--- a/lib/ansible/plugins/filter/network.py
+++ b/lib/ansible/plugins/filter/network.py
@@ -32,9 +32,9 @@ from ansible.module_utils.network.common.utils import Template
from ansible.module_utils.six import iteritems, string_types
from ansible.module_utils.common._collections_compat import Mapping
from ansible.errors import AnsibleError, AnsibleFilterError
+from ansible.utils.display import Display
from ansible.utils.encrypt import random_password
-
try:
import yaml
HAS_YAML = True
@@ -47,19 +47,14 @@ try:
except ImportError:
HAS_TEXTFSM = False
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
try:
from passlib.hash import md5_crypt
HAS_PASSLIB = True
except ImportError:
HAS_PASSLIB = False
+display = Display()
+
def re_matchall(regex, value):
objects = list()
diff --git a/lib/ansible/plugins/httpapi/eos.py b/lib/ansible/plugins/httpapi/eos.py
index 8539375b93..c9e7a114b6 100644
--- a/lib/ansible/plugins/httpapi/eos.py
+++ b/lib/ansible/plugins/httpapi/eos.py
@@ -11,12 +11,9 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.httpapi import HttpApiBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class HttpApi(HttpApiBase):
diff --git a/lib/ansible/plugins/httpapi/ftd.py b/lib/ansible/plugins/httpapi/ftd.py
index f154b35131..4196334be7 100644
--- a/lib/ansible/plugins/httpapi/ftd.py
+++ b/lib/ansible/plugins/httpapi/ftd.py
@@ -60,6 +60,7 @@ from ansible.plugins.httpapi import HttpApiBase
from urllib3 import encode_multipart_formdata
from urllib3.fields import RequestField
from ansible.module_utils.connection import ConnectionError
+from ansible.utils.display import Display
BASE_HEADERS = {
'Content-Type': 'application/json',
@@ -69,12 +70,7 @@ BASE_HEADERS = {
TOKEN_EXPIRATION_STATUS_CODE = 408
UNAUTHORIZED_STATUS_CODE = 401
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
-
- display = Display()
+display = Display()
class HttpApi(HttpApiBase):
diff --git a/lib/ansible/plugins/httpapi/nxos.py b/lib/ansible/plugins/httpapi/nxos.py
index 3912de08f3..4d065bf4c8 100644
--- a/lib/ansible/plugins/httpapi/nxos.py
+++ b/lib/ansible/plugins/httpapi/nxos.py
@@ -10,12 +10,9 @@ from ansible.module_utils._text import to_text
from ansible.module_utils.connection import ConnectionError
from ansible.module_utils.network.common.utils import to_list
from ansible.plugins.httpapi import HttpApiBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class HttpApi(HttpApiBase):
diff --git a/lib/ansible/plugins/inventory/__init__.py b/lib/ansible/plugins/inventory/__init__.py
index 3cd8f43f51..a85f075b9a 100644
--- a/lib/ansible/plugins/inventory/__init__.py
+++ b/lib/ansible/plugins/inventory/__init__.py
@@ -33,12 +33,9 @@ from ansible.module_utils.common._collections_compat import Mapping
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.module_utils.six import string_types
from ansible.template import Templar
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
_SAFE_GROUP = re.compile("[^A-Za-z0-9_]")
diff --git a/lib/ansible/plugins/inventory/aws_ec2.py b/lib/ansible/plugins/inventory/aws_ec2.py
index da4ad1c58a..977d94e044 100644
--- a/lib/ansible/plugins/inventory/aws_ec2.py
+++ b/lib/ansible/plugins/inventory/aws_ec2.py
@@ -133,12 +133,7 @@ from ansible.module_utils.six import string_types
from ansible.module_utils.ec2 import ansible_dict_to_boto3_filter_list, boto3_tag_list_to_ansible_dict
from ansible.module_utils.ec2 import camel_dict_to_snake_dict
from ansible.plugins.inventory import BaseInventoryPlugin, Constructable, Cacheable, to_safe_group_name
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
+from ansible.utils.display import Display
try:
import boto3
@@ -146,6 +141,8 @@ try:
except ImportError:
raise AnsibleError('The ec2 dynamic inventory plugin requires boto3 and botocore.')
+display = Display()
+
# The mappings give an array of keys to get from the filter name to the value
# returned by boto3's EC2 describe_instances method.
diff --git a/lib/ansible/plugins/inventory/toml.py b/lib/ansible/plugins/inventory/toml.py
index ea0c19b611..bc3105d467 100644
--- a/lib/ansible/plugins/inventory/toml.py
+++ b/lib/ansible/plugins/inventory/toml.py
@@ -100,6 +100,7 @@ from ansible.module_utils.common._collections_compat import MutableMapping, Muta
from ansible.module_utils.six import string_types, text_type
from ansible.parsing.yaml.objects import AnsibleSequence, AnsibleUnicode
from ansible.plugins.inventory import BaseFileInventoryPlugin
+from ansible.utils.display import Display
try:
import toml
@@ -107,12 +108,7 @@ try:
except ImportError:
HAS_TOML = False
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
+display = Display()
WARNING_MSG = (
'The TOML inventory format is marked as preview, which means that it is not guaranteed to have a backwards '
diff --git a/lib/ansible/plugins/loader.py b/lib/ansible/plugins/loader.py
index a6927e18a3..ac94a22cc5 100644
--- a/lib/ansible/plugins/loader.py
+++ b/lib/ansible/plugins/loader.py
@@ -21,13 +21,10 @@ from ansible.errors import AnsibleError
from ansible.module_utils._text import to_text
from ansible.parsing.utils.yaml import from_yaml
from ansible.plugins import get_plugin_class, MODULE_CACHE, PATH_CACHE, PLUGIN_PATH_CACHE
+from ansible.utils.display import Display
from ansible.utils.plugin_docs import get_docstring
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def get_all_plugin_loaders():
diff --git a/lib/ansible/plugins/lookup/__init__.py b/lib/ansible/plugins/lookup/__init__.py
index 31038ea03e..42f0d1cc46 100644
--- a/lib/ansible/plugins/lookup/__init__.py
+++ b/lib/ansible/plugins/lookup/__init__.py
@@ -23,12 +23,9 @@ from abc import abstractmethod
from ansible.errors import AnsibleFileNotFound
from ansible.plugins import AnsiblePlugin
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['LookupBase']
diff --git a/lib/ansible/plugins/lookup/aws_ssm.py b/lib/ansible/plugins/lookup/aws_ssm.py
index 0e85a26fc9..13fd888e45 100644
--- a/lib/ansible/plugins/lookup/aws_ssm.py
+++ b/lib/ansible/plugins/lookup/aws_ssm.py
@@ -103,12 +103,7 @@ from ansible.module_utils._text import to_native
from ansible.module_utils.ec2 import HAS_BOTO3, boto3_tag_list_to_ansible_dict
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
try:
from botocore.exceptions import ClientError
@@ -117,6 +112,8 @@ try:
except ImportError:
pass # will be captured by imported HAS_BOTO3
+display = Display()
+
def _boto3_conn(region, credentials):
if 'boto_profile' in credentials:
diff --git a/lib/ansible/plugins/lookup/conjur_variable.py b/lib/ansible/plugins/lookup/conjur_variable.py
index 20e6a70424..26a488effb 100644
--- a/lib/ansible/plugins/lookup/conjur_variable.py
+++ b/lib/ansible/plugins/lookup/conjur_variable.py
@@ -64,13 +64,9 @@ from ansible.module_utils.six.moves.urllib.parse import quote_plus
import yaml
from ansible.module_utils.urls import open_url
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# Load configuration and return as dictionary if file is present on file system
diff --git a/lib/ansible/plugins/lookup/cpm_metering.py b/lib/ansible/plugins/lookup/cpm_metering.py
index dbc764faaa..34cff8ff0c 100644
--- a/lib/ansible/plugins/lookup/cpm_metering.py
+++ b/lib/ansible/plugins/lookup/cpm_metering.py
@@ -111,12 +111,9 @@ from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_text, to_bytes, to_native
from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/lookup/cyberarkpassword.py b/lib/ansible/plugins/lookup/cyberarkpassword.py
index 9ae4cdb056..348a66f878 100644
--- a/lib/ansible/plugins/lookup/cyberarkpassword.py
+++ b/lib/ansible/plugins/lookup/cyberarkpassword.py
@@ -73,12 +73,9 @@ from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.parsing.splitter import parse_kv
from ansible.module_utils._text import to_text
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
CLIPASSWORDSDK_CMD = os.getenv('AIM_CLIPASSWORDSDK_CMD', '/opt/CARKaim/sdk/clipasswordsdk')
diff --git a/lib/ansible/plugins/lookup/file.py b/lib/ansible/plugins/lookup/file.py
index 4e4bdab536..3ce41559bd 100644
--- a/lib/ansible/plugins/lookup/file.py
+++ b/lib/ansible/plugins/lookup/file.py
@@ -50,12 +50,9 @@ RETURN = """
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_text
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/lookup/filetree.py b/lib/ansible/plugins/lookup/filetree.py
index 003214f70d..83b52f389f 100644
--- a/lib/ansible/plugins/lookup/filetree.py
+++ b/lib/ansible/plugins/lookup/filetree.py
@@ -99,12 +99,9 @@ except ImportError:
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_native, to_text
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# If selinux fails to find a default, return an array of None
diff --git a/lib/ansible/plugins/lookup/grafana_dashboard.py b/lib/ansible/plugins/lookup/grafana_dashboard.py
index fd7985bf67..2a9c7b498e 100644
--- a/lib/ansible/plugins/lookup/grafana_dashboard.py
+++ b/lib/ansible/plugins/lookup/grafana_dashboard.py
@@ -67,12 +67,9 @@ from ansible.plugins.lookup import LookupBase
from ansible.module_utils.urls import open_url
from ansible.module_utils._text import to_bytes, to_native
from ansible.module_utils.six.moves.urllib.error import HTTPError
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
ANSIBLE_GRAFANA_URL = 'http://127.0.0.1:3000'
diff --git a/lib/ansible/plugins/lookup/keyring.py b/lib/ansible/plugins/lookup/keyring.py
index 578ec60784..1fd441a387 100644
--- a/lib/ansible/plugins/lookup/keyring.py
+++ b/lib/ansible/plugins/lookup/keyring.py
@@ -36,21 +36,17 @@ RETURN = """
HAS_KEYRING = True
from ansible.errors import AnsibleError
+from ansible.utils.display import Display
try:
import keyring
except ImportError:
HAS_KEYRING = False
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
-
from ansible.plugins.lookup import LookupBase
+display = Display()
+
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/lookup/rabbitmq.py b/lib/ansible/plugins/lookup/rabbitmq.py
index cc4ee91b9f..2596359c9b 100644
--- a/lib/ansible/plugins/lookup/rabbitmq.py
+++ b/lib/ansible/plugins/lookup/rabbitmq.py
@@ -97,16 +97,12 @@ RETURN = """
"""
+import json
+
from ansible.errors import AnsibleError, AnsibleParserError
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_native, to_text
-import json
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+from ansible.utils.display import Display
try:
import pika
@@ -115,6 +111,8 @@ try:
except ImportError:
HAS_PIKA = False
+display = Display()
+
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/lookup/template.py b/lib/ansible/plugins/lookup/template.py
index 7a25a5be18..1388547090 100644
--- a/lib/ansible/plugins/lookup/template.py
+++ b/lib/ansible/plugins/lookup/template.py
@@ -38,12 +38,9 @@ from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from ansible.module_utils._text import to_bytes, to_text
from ansible.template import generate_ansible_template_vars
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/lookup/url.py b/lib/ansible/plugins/lookup/url.py
index 16557531e7..8de299cdbb 100644
--- a/lib/ansible/plugins/lookup/url.py
+++ b/lib/ansible/plugins/lookup/url.py
@@ -60,12 +60,9 @@ from ansible.module_utils.six.moves.urllib.error import HTTPError, URLError
from ansible.module_utils._text import to_text, to_native
from ansible.module_utils.urls import open_url, ConnectionError, SSLValidationError
from ansible.plugins.lookup import LookupBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class LookupModule(LookupBase):
diff --git a/lib/ansible/plugins/netconf/ce.py b/lib/ansible/plugins/netconf/ce.py
index 7c92395e0e..bdec1481e5 100644
--- a/lib/ansible/plugins/netconf/ce.py
+++ b/lib/ansible/plugins/netconf/ce.py
@@ -27,6 +27,7 @@ from ansible.module_utils._text import to_text, to_bytes, to_native
from ansible.errors import AnsibleConnectionFailure, AnsibleError
from ansible.plugins.netconf import NetconfBase
from ansible.plugins.netconf import ensure_connected
+from ansible.utils.display import Display
try:
from ncclient import manager
@@ -36,11 +37,7 @@ try:
except ImportError:
raise AnsibleError("ncclient is not installed")
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class Netconf(NetconfBase):
diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py
index 26f359f0a9..41b74edabd 100644
--- a/lib/ansible/plugins/strategy/__init__.py
+++ b/lib/ansible/plugins/strategy/__init__.py
@@ -47,15 +47,11 @@ from ansible.playbook.task_include import TaskInclude
from ansible.playbook.role_include import IncludeRole
from ansible.plugins.loader import action_loader, connection_loader, filter_loader, lookup_loader, module_loader, test_loader
from ansible.template import Templar
+from ansible.utils.display import Display
from ansible.utils.vars import combine_vars
from ansible.vars.clean import strip_internal_keys
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['StrategyBase']
diff --git a/lib/ansible/plugins/strategy/free.py b/lib/ansible/plugins/strategy/free.py
index 808843cb28..bd94338567 100644
--- a/lib/ansible/plugins/strategy/free.py
+++ b/lib/ansible/plugins/strategy/free.py
@@ -40,13 +40,9 @@ from ansible.plugins.loader import action_loader
from ansible.plugins.strategy import StrategyBase
from ansible.template import Templar
from ansible.module_utils._text import to_text
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class StrategyModule(StrategyBase):
diff --git a/lib/ansible/plugins/strategy/host_pinned.py b/lib/ansible/plugins/strategy/host_pinned.py
index 52cf488017..ba293d3651 100644
--- a/lib/ansible/plugins/strategy/host_pinned.py
+++ b/lib/ansible/plugins/strategy/host_pinned.py
@@ -33,13 +33,9 @@ DOCUMENTATION = '''
'''
from ansible.plugins.strategy.free import StrategyModule as FreeStrategyModule
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class StrategyModule(FreeStrategyModule):
diff --git a/lib/ansible/plugins/strategy/linear.py b/lib/ansible/plugins/strategy/linear.py
index 6db63dc558..0a985ad90d 100644
--- a/lib/ansible/plugins/strategy/linear.py
+++ b/lib/ansible/plugins/strategy/linear.py
@@ -41,13 +41,9 @@ from ansible.playbook.task import Task
from ansible.plugins.loader import action_loader
from ansible.plugins.strategy import StrategyBase
from ansible.template import Templar
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class StrategyModule(StrategyBase):
diff --git a/lib/ansible/plugins/terminal/junos.py b/lib/ansible/plugins/terminal/junos.py
index c954ebcf40..9f4d79276d 100644
--- a/lib/ansible/plugins/terminal/junos.py
+++ b/lib/ansible/plugins/terminal/junos.py
@@ -24,13 +24,9 @@ import re
from ansible.plugins.terminal import TerminalBase
from ansible.errors import AnsibleConnectionFailure
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class TerminalModule(TerminalBase):
diff --git a/lib/ansible/plugins/terminal/routeros.py b/lib/ansible/plugins/terminal/routeros.py
index 11ddab8c0e..48eb119eb6 100644
--- a/lib/ansible/plugins/terminal/routeros.py
+++ b/lib/ansible/plugins/terminal/routeros.py
@@ -25,12 +25,9 @@ import re
from ansible.errors import AnsibleConnectionFailure
from ansible.module_utils._text import to_text, to_bytes
from ansible.plugins.terminal import TerminalBase
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class TerminalModule(TerminalBase):
diff --git a/lib/ansible/plugins/test/core.py b/lib/ansible/plugins/test/core.py
index 8ae39eec67..1c3a570ce4 100644
--- a/lib/ansible/plugins/test/core.py
+++ b/lib/ansible/plugins/test/core.py
@@ -25,12 +25,9 @@ from distutils.version import LooseVersion, StrictVersion
from ansible import errors
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSequence
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def failed(result):
diff --git a/lib/ansible/plugins/vars/__init__.py b/lib/ansible/plugins/vars/__init__.py
index 6540c47fc0..668c92f5fe 100644
--- a/lib/ansible/plugins/vars/__init__.py
+++ b/lib/ansible/plugins/vars/__init__.py
@@ -19,12 +19,9 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.utils.path import basedir
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class BaseVarsPlugin(object):
diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py
index adb9618690..e7de0f893d 100644
--- a/lib/ansible/template/__init__.py
+++ b/lib/ansible/template/__init__.py
@@ -49,13 +49,10 @@ from ansible.plugins.loader import filter_loader, lookup_loader, test_loader
from ansible.template.safe_eval import safe_eval
from ansible.template.template import AnsibleJ2Template
from ansible.template.vars import AnsibleJ2Vars
+from ansible.utils.display import Display
from ansible.utils.unsafe_proxy import UnsafeProxy, wrap_var
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['Templar', 'generate_ansible_template_vars']
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py
index 2f21646467..51117761e1 100644
--- a/lib/ansible/utils/display.py
+++ b/lib/ansible/utils/display.py
@@ -36,7 +36,9 @@ from termios import TIOCGWINSZ
from ansible import constants as C
from ansible.errors import AnsibleError
from ansible.module_utils._text import to_bytes, to_text
+from ansible.module_utils.six import with_metaclass
from ansible.utils.color import stringc
+from ansible.utils.singleton import Singleton
try:
@@ -77,7 +79,7 @@ b_COW_PATHS = (
)
-class Display:
+class Display(with_metaclass(Singleton, object)):
def __init__(self, verbosity=0):
diff --git a/lib/ansible/utils/encrypt.py b/lib/ansible/utils/encrypt.py
index 4445fb87c8..46029037b8 100644
--- a/lib/ansible/utils/encrypt.py
+++ b/lib/ansible/utils/encrypt.py
@@ -16,6 +16,7 @@ from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleAssertionError
from ansible.module_utils.six import text_type
from ansible.module_utils._text import to_text, to_bytes
+from ansible.utils.display import Display
PASSLIB_AVAILABLE = False
try:
@@ -27,11 +28,7 @@ try:
except:
pass
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
__all__ = ['do_encrypt']
diff --git a/lib/ansible/utils/jsonrpc.py b/lib/ansible/utils/jsonrpc.py
index 794f1f4aea..d285cef688 100644
--- a/lib/ansible/utils/jsonrpc.py
+++ b/lib/ansible/utils/jsonrpc.py
@@ -9,13 +9,9 @@ import traceback
from ansible.module_utils._text import to_text
from ansible.module_utils.six import binary_type
+from ansible.utils.display import Display
-
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
class JsonRpcServer(object):
diff --git a/lib/ansible/utils/plugin_docs.py b/lib/ansible/utils/plugin_docs.py
index c13c6529bc..30816462db 100644
--- a/lib/ansible/utils/plugin_docs.py
+++ b/lib/ansible/utils/plugin_docs.py
@@ -10,12 +10,9 @@ from ansible.module_utils._text import to_native
from ansible.module_utils.common._collections_compat import MutableMapping, MutableSet, MutableSequence
from ansible.parsing.plugin_docs import read_docstring, read_docstub
from ansible.parsing.yaml.loader import AnsibleLoader
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
# modules that are ok that they do not have documentation strings
diff --git a/lib/ansible/utils/singleton.py b/lib/ansible/utils/singleton.py
new file mode 100644
index 0000000000..4299403eae
--- /dev/null
+++ b/lib/ansible/utils/singleton.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2017 Ansible Project
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+# Make coding more python3-ish
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+from threading import RLock
+
+
+class Singleton(type):
+ """Metaclass for classes that wish to implement Singleton
+ functionality. If an instance of the class exists, it's returned,
+ otherwise a single instance is instantiated and returned.
+ """
+ def __init__(cls, name, bases, dct):
+ super(Singleton, cls).__init__(name, bases, dct)
+ cls.__instance = None
+ cls.__rlock = RLock()
+
+ def __call__(cls, *args, **kw):
+ if cls.__instance is not None:
+ return cls.__instance
+
+ with cls.__rlock:
+ if cls.__instance is None:
+ cls.__instance = super(Singleton, cls).__call__(*args, **kw)
+
+ return cls.__instance
diff --git a/lib/ansible/vars/clean.py b/lib/ansible/vars/clean.py
index 7b29383c2e..f98d3b77d5 100644
--- a/lib/ansible/vars/clean.py
+++ b/lib/ansible/vars/clean.py
@@ -12,12 +12,9 @@ from ansible import constants as C
from ansible.module_utils._text import to_text
from ansible.module_utils import six
from ansible.plugins.loader import connection_loader
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def module_response_deepcopy(v):
diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py
index 84658e2827..439f2d8beb 100644
--- a/lib/ansible/vars/manager.py
+++ b/lib/ansible/vars/manager.py
@@ -41,16 +41,13 @@ from ansible.module_utils.six import iteritems, text_type, string_types
from ansible.plugins.loader import lookup_loader, vars_loader
from ansible.plugins.cache import FactCache
from ansible.template import Templar
+from ansible.utils.display import Display
from ansible.utils.listify import listify_lookup_plugin_terms
from ansible.utils.vars import combine_vars
from ansible.utils.unsafe_proxy import wrap_var
from ansible.vars.clean import namespace_facts, clean_facts
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def preprocess_vars(a):
diff --git a/lib/ansible/vars/reserved.py b/lib/ansible/vars/reserved.py
index 16d44ef684..d7daea0705 100644
--- a/lib/ansible/vars/reserved.py
+++ b/lib/ansible/vars/reserved.py
@@ -23,12 +23,9 @@ from ansible.playbook import Play
from ansible.playbook.block import Block
from ansible.playbook.role import Role
from ansible.playbook.task import Task
+from ansible.utils.display import Display
-try:
- from __main__ import display
-except ImportError:
- from ansible.utils.display import Display
- display = Display()
+display = Display()
def get_reserved_names(include_private=True):
diff --git a/test/sanity/code-smell/no-main-display.json b/test/sanity/code-smell/no-main-display.json
new file mode 100644
index 0000000000..779b3d07bb
--- /dev/null
+++ b/test/sanity/code-smell/no-main-display.json
@@ -0,0 +1,10 @@
+{
+ "extensions": [
+ ".py"
+ ],
+ "prefixes": [
+ "bin/",
+ "lib/ansible/"
+ ],
+ "output": "path-line-column-message"
+}
diff --git a/test/sanity/code-smell/no-main-display.py b/test/sanity/code-smell/no-main-display.py
new file mode 100755
index 0000000000..71fbc63859
--- /dev/null
+++ b/test/sanity/code-smell/no-main-display.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+from __future__ import print_function
+
+import os
+import re
+import sys
+
+MAIN_DISPLAY_IMPORT = 'from __main__ import display'
+
+
+def main():
+ skip = set()
+
+ for path in sys.argv[1:] or sys.stdin.read().splitlines():
+ if path in skip:
+ continue
+
+ with open(path, 'r') as f:
+ for i, line in enumerate(f.readlines()):
+ if MAIN_DISPLAY_IMPORT in line:
+ lineno = i + 1
+ colno = line.index(MAIN_DISPLAY_IMPORT) + 1
+ print('%s:%d:%d: Display is a singleton, just import and instantiate' % (path, lineno, colno))
+
+
+if __name__ == '__main__':
+ main()