mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-03-26 21:33:12 +00:00
Removes dependency on StormSSH (#6117)
* included storm config parser * Add changelog fragment * Fix changelog fragment * address PR feedback * fix license * add required boilerplate, fix issues found in test output * move __future__ imports * address pr feedback * address test output * address pr feedback
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
DOCUMENTATION = r'''
|
||||
@@ -101,7 +102,7 @@ options:
|
||||
type: str
|
||||
version_added: 6.1.0
|
||||
requirements:
|
||||
- StormSSH
|
||||
- paramiko
|
||||
'''
|
||||
|
||||
EXAMPLES = r'''
|
||||
@@ -160,26 +161,20 @@ hosts_change_diff:
|
||||
'''
|
||||
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from copy import deepcopy
|
||||
|
||||
STORM_IMP_ERR = None
|
||||
try:
|
||||
from storm.parsers.ssh_config_parser import ConfigParser
|
||||
HAS_STORM = True
|
||||
except ImportError:
|
||||
HAS_STORM = False
|
||||
STORM_IMP_ERR = traceback.format_exc()
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
||||
from ansible.module_utils.common.text.converters import to_native
|
||||
from ansible_collections.community.general.plugins.module_utils._stormssh import ConfigParser, HAS_PARAMIKO, PARAMIKO_IMPORT_ERROR
|
||||
from ansible_collections.community.general.plugins.module_utils.ssh import determine_config_file
|
||||
|
||||
|
||||
class SSHConfig():
|
||||
class SSHConfig(object):
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
if not HAS_PARAMIKO:
|
||||
module.fail_json(msg=missing_required_lib('PARAMIKO'), exception=PARAMIKO_IMPORT_ERROR)
|
||||
self.params = module.params
|
||||
self.user = self.params.get('user')
|
||||
self.group = self.params.get('group') or self.user
|
||||
@@ -265,7 +260,8 @@ class SSHConfig():
|
||||
try:
|
||||
self.config.write_to_ssh_config()
|
||||
except PermissionError as perm_exec:
|
||||
self.module.fail_json(msg="Failed to write to %s due to permission issue: %s" % (self.config_file, to_native(perm_exec)))
|
||||
self.module.fail_json(
|
||||
msg="Failed to write to %s due to permission issue: %s" % (self.config_file, to_native(perm_exec)))
|
||||
# Make sure we set the permission
|
||||
perm_mode = '0600'
|
||||
if self.config_file == '/etc/ssh/ssh_config':
|
||||
@@ -327,10 +323,6 @@ def main():
|
||||
],
|
||||
)
|
||||
|
||||
if not HAS_STORM:
|
||||
module.fail_json(changed=False, msg=missing_required_lib("stormssh"),
|
||||
exception=STORM_IMP_ERR)
|
||||
|
||||
ssh_config_obj = SSHConfig(module)
|
||||
ssh_config_obj.ensure_state()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user