| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_ssh_server |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_ssh_server |
| 17 |
version_added: '3.1.0' |
| 18 |
short_description: Manage SSH server configurations on SONiC |
| 19 |
description: |
| 20 |
- This module provides SSH server configuration management to specify the |
| 21 |
algorithms used for SSH connection in devices running SONiC. |
| 22 |
author: Bhavesh (@bhaveshdell) |
| 23 |
options: |
| 24 |
config: |
| 25 |
description: |
| 26 |
- SSH servers use the following configurations for SSH connections. |
| 27 |
type: dict |
| 28 |
suboptions: |
| 29 |
server_globals: |
| 30 |
description: |
| 31 |
- SSH server global configuration. |
| 32 |
- For options of 'str' type, deletion results in restoring them to their default values. |
| 33 |
type: dict |
| 34 |
suboptions: |
| 35 |
password_authentication: |
| 36 |
description: |
| 37 |
- Configure password authentication on ssh server. |
| 38 |
- By default it is enabled. |
| 39 |
- Default is True. |
| 40 |
type: bool |
| 41 |
publickey_authentication: |
| 42 |
description: |
| 43 |
- Configure publickey authentication on ssh server. |
| 44 |
- Default is True. |
| 45 |
type: bool |
| 46 |
max_auth_retries: |
| 47 |
description: |
| 48 |
- Number of authentication retries allowed before session terminates. |
| 49 |
- Range 0-10. |
| 50 |
- Default is 6. |
| 51 |
type: int |
| 52 |
disable_forwarding: |
| 53 |
description: |
| 54 |
- Configure disable forwarding on ssh server. |
| 55 |
- Default is False. |
| 56 |
type: bool |
| 57 |
permit_root_login: |
| 58 |
description: |
| 59 |
- Configure permit root login on ssh server. |
| 60 |
- Default is False. |
| 61 |
type: bool |
| 62 |
permit_user_rc: |
| 63 |
description: |
| 64 |
- Configure permit user rc on ssh server. |
| 65 |
- Default is True. |
| 66 |
type: bool |
| 67 |
x11_forwarding: |
| 68 |
description: |
| 69 |
- Configure x11 forwarding on ssh server. |
| 70 |
- Default is False. |
| 71 |
type: bool |
| 72 |
permit_user_environment: |
| 73 |
description: |
| 74 |
- Configure permit user environment on ssh server. |
| 75 |
- Default is False. |
| 76 |
type: bool |
| 77 |
ciphers: |
| 78 |
description: |
| 79 |
- Configure ciphers on ssh server. |
| 80 |
- Defaults are aes128-ctr,aes192-ctr,aes256-ctr,[email protected], |
| 81 |
[email protected],[email protected]. |
| 82 |
type: str |
| 83 |
macs: |
| 84 |
description: |
| 85 |
- Configure macs on ssh server. |
| 86 |
- Defaults are [email protected],[email protected], |
| 87 |
[email protected],[email protected],hmac-sha2-256,hmac-sha2-512. |
| 88 |
type: str |
| 89 |
kexalgorithms: |
| 90 |
description: |
| 91 |
- Configure key exchange algorithms. |
| 92 |
- Defaults are curve25519-sha256,[email protected],ecdh-sha2-nistp256, |
| 93 |
ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256, |
| 94 |
diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256, |
| 95 |
type: str |
| 96 |
hostkeyalgorithms: |
| 97 |
description: |
| 98 |
- Configure hostkey algorithms on ssh server. |
| 99 |
- Defaults are ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-256,rsa-sha2-512,ssh-rsa. |
| 100 |
type: str |
| 101 |
state: |
| 102 |
description: |
| 103 |
- The state of the configuration after module completion. |
| 104 |
type: str |
| 105 |
choices: |
| 106 |
- merged |
| 107 |
- deleted |
| 108 |
- replaced |
| 109 |
- overridden |
| 110 |
default: merged |
| 111 |
""" |
| 112 |
|
| 113 |
EXAMPLES = """ |
| 114 |
# Using "deleted" state |
| 115 |
# |
| 116 |
# Before state: |
| 117 |
# ------------- |
| 118 |
# |
| 119 |
# sonic# show running-configuration | grep "ip ssh" |
| 120 |
# ip ssh disable-publickey-authentication true |
| 121 |
# sonic# |
| 122 |
|
| 123 |
- name: Delete specified SSH configurations |
| 124 |
dellemc.enterprise_sonic.sonic_ssh_server: |
| 125 |
config: |
| 126 |
server_globals: |
| 127 |
publickey_authentication: false |
| 128 |
state: deleted |
| 129 |
|
| 130 |
# After state: |
| 131 |
# ------------ |
| 132 |
# |
| 133 |
# sonic# show running-configuration | grep "ip ssh" |
| 134 |
# ip ssh disable-publickey-authentication false |
| 135 |
# sonic# |
| 136 |
|
| 137 |
|
| 138 |
# Using "merged" state |
| 139 |
# |
| 140 |
# Before state: |
| 141 |
# ------------- |
| 142 |
# |
| 143 |
# sonic# show running-configuration | grep "ip ssh" |
| 144 |
# ip ssh disable-publickey-authentication false |
| 145 |
# sonic# |
| 146 |
|
| 147 |
- name: Modify SSH configurations |
| 148 |
dellemc.enterprise_sonic.sonic_ssh_server: |
| 149 |
config: |
| 150 |
server_globals: |
| 151 |
publickey_authentication: false |
| 152 |
state: merged |
| 153 |
|
| 154 |
# After state: |
| 155 |
# ------------ |
| 156 |
# |
| 157 |
# sonic# show running-configuration | grep "ip ssh" |
| 158 |
# ip ssh disable-publickey-authentication true |
| 159 |
# sonic# |
| 160 |
|
| 161 |
|
| 162 |
# Using "replaced" state |
| 163 |
# |
| 164 |
# Before state: |
| 165 |
# ------------- |
| 166 |
# |
| 167 |
# sonic# show running-configuration | grep "ip ssh client" |
| 168 |
# ip ssh client ciphers aes192-ctr,[email protected] |
| 169 |
# ip ssh client kexalgorithms curve25519-sha256,diffie-hellman-group16-sha512 |
| 170 |
# ip ssh client macs [email protected],[email protected] |
| 171 |
# sonic# |
| 172 |
|
| 173 |
- name: Replace SSH configurations |
| 174 |
dellemc.enterprise_sonic.sonic_ssh: |
| 175 |
config: |
| 176 |
server_globals: |
| 177 |
cipher: 'aes256-ctr' |
| 178 |
kex: 'curve25519-sha256,diffie-hellman-group16-sha512' |
| 179 |
state: replaced |
| 180 |
|
| 181 |
# After state: |
| 182 |
# ------------ |
| 183 |
# |
| 184 |
# sonic# show running-configuration | grep "ip ssh client" |
| 185 |
# ip ssh client ciphers aes256-ctr |
| 186 |
# ip ssh client kexalgorithms curve25519-sha256,diffie-hellman-group16-sha512 |
| 187 |
# sonic# |
| 188 |
|
| 189 |
|
| 190 |
# Using "overridden" state |
| 191 |
# |
| 192 |
# Before state: |
| 193 |
# ------------- |
| 194 |
# |
| 195 |
# sonic# show running-configuration | grep "ip ssh" |
| 196 |
# ip ssh disable-publickey-authentication false |
| 197 |
# sonic# |
| 198 |
|
| 199 |
- name: Override SSH configurations |
| 200 |
dellemc.enterprise_sonic.sonic_ssh: |
| 201 |
config: |
| 202 |
server_globals: |
| 203 |
publickey_authentication: false |
| 204 |
state: overridden |
| 205 |
|
| 206 |
# After state: |
| 207 |
# ------------ |
| 208 |
# |
| 209 |
# sonic# show running-configuration | grep "ip ssh" |
| 210 |
# ip ssh disable-publickey-authentication true |
| 211 |
# sonic# |
| 212 |
""" |
| 213 |
|
| 214 |
RETURN = """ |
| 215 |
before: |
| 216 |
description: The configuration prior to the model invocation. |
| 217 |
returned: always |
| 218 |
type: dict |
| 219 |
sample: > |
| 220 |
The configuration returned will always be in the same format |
| 221 |
of the parameters above. |
| 222 |
after: |
| 223 |
description: The configuration resulting from module invocation. |
| 224 |
returned: when changed |
| 225 |
type: dict |
| 226 |
sample: > |
| 227 |
The configuration returned will always be in the same format |
| 228 |
of the parameters above. |
| 229 |
after_generated: |
| 230 |
description: The configuration that would be generated by module invocation in non-check mode. |
| 231 |
returned: when C(check_mode) |
| 232 |
type: dict |
| 233 |
sample: > |
| 234 |
The configuration returned will always be in the same format |
| 235 |
as the parameters above. |
| 236 |
commands: |
| 237 |
description: The set of commands pushed to the remote device. |
| 238 |
returned: always |
| 239 |
type: list |
| 240 |
sample: ['command 1', 'command 2', 'command 3'] |
| 241 |
""" |
| 242 |
|
| 243 |
|
| 244 |
from ansible.module_utils.basic import AnsibleModule |
| 245 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.ssh_server.ssh_server import Ssh_serverArgs |
| 246 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.ssh_server.ssh_server import Ssh_server |
| 247 |
|
| 248 |
|
| 249 |
def main(): |
| 250 |
""" |
| 251 |
Main entry point for module execution |
| 252 |
|
| 253 |
:returns: the result form module invocation |
| 254 |
""" |
| 255 |
module = AnsibleModule(argument_spec=Ssh_serverArgs.argument_spec, |
| 256 |
supports_check_mode=True) |
| 257 |
|
| 258 |
result = Ssh_server(module).execute_module() |
| 259 |
module.exit_json(**result) |
| 260 |
|
| 261 |
|
| 262 |
if __name__ == '__main__': |
| 263 |
main() |