mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-22 02:36:11 +00:00
library: don't create AnsibleUtil.module lazily
Now, that we only create the AnsibleUtil instance when we already know that we run under ansible (not from unit tests), we can avoid initializing the AnsibleModule lazily.
This commit is contained in:
parent
4e6ace727e
commit
8db7f496b2
1 changed files with 7 additions and 13 deletions
|
|
@ -2004,21 +2004,15 @@ class AnsibleUtil(RunEnvironment):
|
|||
|
||||
def __init__(self):
|
||||
RunEnvironment.__init__(self)
|
||||
self._module = None
|
||||
self._run_results = []
|
||||
self._log_idx = 0
|
||||
|
||||
@property
|
||||
def module(self):
|
||||
module = self._module
|
||||
if module is None:
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
module = AnsibleModule(
|
||||
argument_spec = self.ARGS,
|
||||
supports_check_mode = True,
|
||||
)
|
||||
self._module = module
|
||||
return module
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
module = AnsibleModule(
|
||||
argument_spec = self.ARGS,
|
||||
supports_check_mode = True,
|
||||
)
|
||||
self.module = module
|
||||
|
||||
def run_command(self, argv, encoding = None):
|
||||
return self.module.run_command(argv, encoding = encoding)
|
||||
|
|
@ -2681,9 +2675,9 @@ class Cmd_initscripts(Cmd):
|
|||
###############################################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
ansible_util = AnsibleUtil()
|
||||
connections = None
|
||||
cmd = None
|
||||
ansible_util = AnsibleUtil()
|
||||
try:
|
||||
params = ansible_util.module.params
|
||||
cmd = Cmd.create(params['provider'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue