| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright 2022 Red Hat |
| 4 |
# GNU General Public License v3.0+ |
| 5 |
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
""" |
| 8 |
The module file for cp_mgmt_hosts |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
|
| 13 |
__metaclass__ = type |
| 14 |
|
| 15 |
DOCUMENTATION = """ |
| 16 |
module: cp_mgmt_hosts |
| 17 |
short_description: Manages HOSTS resource module |
| 18 |
description: |
| 19 |
- This resource module allows for addition, deletion, or modification of CP MGMT Hosts. |
| 20 |
- This resource module also takes care of gathering Hosts config facts |
| 21 |
- Available from R80 management version. |
| 22 |
version_added: "5.0.0" |
| 23 |
author: Ansible Security Automation Team (@justjais) <https://github.com/ansible-security>- |
| 24 |
options: |
| 25 |
config: |
| 26 |
description: A dictionary of HOSTS options |
| 27 |
type: dict |
| 28 |
suboptions: |
| 29 |
name: |
| 30 |
description: Object name. Must be unique in the domain. |
| 31 |
type: str |
| 32 |
ip_address: |
| 33 |
description: IPv4 or IPv6 address. If both addresses are required use ipv4-address |
| 34 |
and ipv6-address fields explicitly. |
| 35 |
type: str |
| 36 |
ipv4_address: |
| 37 |
description: IPv4 address. |
| 38 |
type: str |
| 39 |
ipv6_address: |
| 40 |
description: IPv4 address. |
| 41 |
type: str |
| 42 |
interfaces: |
| 43 |
description: Host interfaces. |
| 44 |
type: list |
| 45 |
elements: dict |
| 46 |
suboptions: |
| 47 |
name: |
| 48 |
description: |
| 49 |
- Interface name. |
| 50 |
type: str |
| 51 |
subnet: |
| 52 |
description: |
| 53 |
- IPv4 or IPv6 network address. |
| 54 |
- If both addresses are required use subnet4 and subnet6 fields explicitly. |
| 55 |
type: str |
| 56 |
subnet4: |
| 57 |
description: |
| 58 |
- IPv4 network address. |
| 59 |
type: str |
| 60 |
subnet6: |
| 61 |
description: |
| 62 |
- IPv6 network address. |
| 63 |
type: str |
| 64 |
mask_length: |
| 65 |
description: |
| 66 |
- IPv4 or IPv6 network mask length. If both masks are required use mask-length4 and |
| 67 |
mask-length6 fields explicitly. |
| 68 |
- Instead of IPv4 mask length it is possible to specify IPv4 mask itself in subnet-mask field. |
| 69 |
type: int |
| 70 |
mask_length4: |
| 71 |
description: |
| 72 |
- IPv4 network mask length. |
| 73 |
type: int |
| 74 |
mask_length6: |
| 75 |
description: |
| 76 |
- IPv6 network mask length. |
| 77 |
type: int |
| 78 |
subnet_mask: |
| 79 |
description: |
| 80 |
- IPv4 network mask. |
| 81 |
type: str |
| 82 |
color: |
| 83 |
description: |
| 84 |
- Color of the object. Should be one of existing colors. |
| 85 |
type: str |
| 86 |
choices: |
| 87 |
- 'aquamarine' |
| 88 |
- 'black' |
| 89 |
- 'blue' |
| 90 |
- 'crete blue' |
| 91 |
- 'burlywood' |
| 92 |
- 'cyan' |
| 93 |
- 'dark green' |
| 94 |
- 'khaki' |
| 95 |
- 'orchid' |
| 96 |
- 'dark orange' |
| 97 |
- 'dark sea green' |
| 98 |
- 'pink' |
| 99 |
- 'turquoise' |
| 100 |
- 'dark blue' |
| 101 |
- 'firebrick' |
| 102 |
- 'brown' |
| 103 |
- 'forest green' |
| 104 |
- 'gold' |
| 105 |
- 'dark gold' |
| 106 |
- 'gray' |
| 107 |
- 'dark gray' |
| 108 |
- 'light green' |
| 109 |
- 'lemon chiffon' |
| 110 |
- 'coral' |
| 111 |
- 'sea green' |
| 112 |
- 'sky blue' |
| 113 |
- 'magenta' |
| 114 |
- 'purple' |
| 115 |
- 'slate blue' |
| 116 |
- 'violet red' |
| 117 |
- 'navy blue' |
| 118 |
- 'olive' |
| 119 |
- 'orange' |
| 120 |
- 'red' |
| 121 |
- 'sienna' |
| 122 |
- 'yellow' |
| 123 |
comments: |
| 124 |
description: |
| 125 |
- Comments string. |
| 126 |
type: str |
| 127 |
details_level: |
| 128 |
description: |
| 129 |
- The level of detail for some of the fields in the response can vary from showing |
| 130 |
only the UID value of the object to a fully detailed representation of the object. |
| 131 |
type: str |
| 132 |
choices: |
| 133 |
- 'uid' |
| 134 |
- 'standard' |
| 135 |
- 'full' |
| 136 |
ignore_warnings: |
| 137 |
description: |
| 138 |
- Apply changes ignoring warnings. |
| 139 |
type: bool |
| 140 |
ignore_errors: |
| 141 |
description: |
| 142 |
- Apply changes ignoring errors. You won't be able to publish such a changes. |
| 143 |
- If ignore-warnings flag was omitted - warnings will also be ignored. |
| 144 |
type: bool |
| 145 |
nat_settings: |
| 146 |
description: NAT settings. |
| 147 |
type: dict |
| 148 |
suboptions: |
| 149 |
auto_rule: |
| 150 |
description: |
| 151 |
- Whether to add automatic address translation rules. |
| 152 |
type: bool |
| 153 |
ip_address: |
| 154 |
description: |
| 155 |
- IPv4 or IPv6 address. If both addresses are required use ipv4-address and ipv6-address fields explicitly. |
| 156 |
- This parameter is not required in case "method" parameter is "hide" and "hide-behind" parameter is "gateway". |
| 157 |
type: str |
| 158 |
ipv4_address: |
| 159 |
description: |
| 160 |
- IPv4 address. |
| 161 |
type: str |
| 162 |
ipv6_address: |
| 163 |
description: |
| 164 |
- IPv6 address. |
| 165 |
type: str |
| 166 |
hide_behind: |
| 167 |
description: |
| 168 |
- Hide behind method. This parameter is not required in case "method" parameter is "static". |
| 169 |
type: str |
| 170 |
choices: |
| 171 |
- 'gateway' |
| 172 |
- 'ip-address' |
| 173 |
install_on: |
| 174 |
description: |
| 175 |
- Which gateway should apply the NAT translation. |
| 176 |
type: str |
| 177 |
method: |
| 178 |
description: |
| 179 |
- NAT translation method. |
| 180 |
type: str |
| 181 |
choices: |
| 182 |
- 'hide' |
| 183 |
- 'static' |
| 184 |
tags: |
| 185 |
description: Collection of tag identifiers. |
| 186 |
type: list |
| 187 |
elements: str |
| 188 |
host_servers: |
| 189 |
description: Servers Configuration. |
| 190 |
type: dict |
| 191 |
suboptions: |
| 192 |
dns_server: |
| 193 |
description: Gets True if this server is a DNS Server. |
| 194 |
type: bool |
| 195 |
mail_server: |
| 196 |
description: Gets True if this server is a Mail Server. |
| 197 |
type: bool |
| 198 |
web_server: |
| 199 |
description: Gets True if this server is a Web Server. |
| 200 |
type: bool |
| 201 |
web_server_config: |
| 202 |
description: Web Server configuration. |
| 203 |
type: dict |
| 204 |
suboptions: |
| 205 |
additional_ports: |
| 206 |
description: |
| 207 |
- Server additional ports. |
| 208 |
type: list |
| 209 |
elements: str |
| 210 |
application_engines: |
| 211 |
description: |
| 212 |
- Application engines of this web server. |
| 213 |
type: list |
| 214 |
elements: str |
| 215 |
listen_standard_port: |
| 216 |
description: |
| 217 |
- Whether server listens to standard port. |
| 218 |
type: bool |
| 219 |
operating_system: |
| 220 |
description: |
| 221 |
- Operating System. |
| 222 |
type: str |
| 223 |
choices: |
| 224 |
- 'sparc linux' |
| 225 |
- 'windows' |
| 226 |
- 'other' |
| 227 |
- 'x86 linux' |
| 228 |
- 'sparc solaris' |
| 229 |
protected_by: |
| 230 |
description: |
| 231 |
- Network object which protects this server identified by the name or UID. |
| 232 |
type: str |
| 233 |
color: |
| 234 |
description: Color of the object. Should be one of existing colors. |
| 235 |
type: str |
| 236 |
choices: |
| 237 |
- aquamarine |
| 238 |
- black |
| 239 |
- blue |
| 240 |
- crete blue |
| 241 |
- burlywood |
| 242 |
- cyan |
| 243 |
- dark green |
| 244 |
- khaki |
| 245 |
- orchid |
| 246 |
- dark orange |
| 247 |
- dark sea green |
| 248 |
- pink |
| 249 |
- turquoise |
| 250 |
- dark blue |
| 251 |
- firebrick |
| 252 |
- brown |
| 253 |
- forest green |
| 254 |
- gold |
| 255 |
- dark gold |
| 256 |
- gray |
| 257 |
- dark gray |
| 258 |
- light green |
| 259 |
- lemon chiffon |
| 260 |
- coral |
| 261 |
- sea green |
| 262 |
- sky blue |
| 263 |
- magenta |
| 264 |
- purple |
| 265 |
- slate blue |
| 266 |
- violet red |
| 267 |
- navy blue |
| 268 |
- olive |
| 269 |
- orange |
| 270 |
- red |
| 271 |
- sienna |
| 272 |
- yellow |
| 273 |
comments: |
| 274 |
description: Comments string. |
| 275 |
type: str |
| 276 |
details_level: |
| 277 |
description: The level of detail for some of the fields in the response can |
| 278 |
vary from showing only the UID value of the object to a fully detailed representation |
| 279 |
of the object. |
| 280 |
type: str |
| 281 |
choices: |
| 282 |
- uid |
| 283 |
- standard |
| 284 |
- full |
| 285 |
groups: |
| 286 |
description: Collection of group identifiers. |
| 287 |
type: list |
| 288 |
elements: str |
| 289 |
ignore_warnings: |
| 290 |
description: Apply changes ignoring warnings. |
| 291 |
type: bool |
| 292 |
ignore_errors: |
| 293 |
description: Apply changes ignoring errors. You won't be able to publish such |
| 294 |
a changes. If ignore-warnings flag was omitted - warnings will also be ignored. |
| 295 |
type: bool |
| 296 |
limit: |
| 297 |
description: |
| 298 |
- The maximal number of returned results. |
| 299 |
- NOTE, this parameter is a valid parameter only for the GATHERED state, for config states |
| 300 |
like, MERGED, REPLACED, and DELETED state it won't be applicable. |
| 301 |
type: int |
| 302 |
offset: |
| 303 |
description: |
| 304 |
- Number of the results to initially skip. |
| 305 |
- NOTE, this parameter is a valid parameter only for the GATHERED state, for config states |
| 306 |
like, MERGED, REPLACED, and DELETED state it won't be applicable. |
| 307 |
type: int |
| 308 |
order: |
| 309 |
description: |
| 310 |
- Sorts results by the given field. By default the results are sorted in the ascending order by name. |
| 311 |
This parameter is relevant only for getting few objects. |
| 312 |
- NOTE, this parameter is a valid parameter only for the GATHERED state, for config states |
| 313 |
like, MERGED, REPLACED, and DELETED state it won't be applicable. |
| 314 |
type: list |
| 315 |
elements: dict |
| 316 |
suboptions: |
| 317 |
ASC: |
| 318 |
description: |
| 319 |
- Sorts results by the given field in ascending order. |
| 320 |
type: str |
| 321 |
DESC: |
| 322 |
description: |
| 323 |
- Sorts results by the given field in descending order. |
| 324 |
type: str |
| 325 |
round_trip: |
| 326 |
description: |
| 327 |
- If set to True, the round trip will filter out the module parameters from the response param, |
| 328 |
which will enable the user to fire the config request using the structured gathered data. |
| 329 |
- NOTE, this parameter makes relevance only with the GATHERED state, as for config states like, |
| 330 |
MERGED, REPLACED, and DELETED state it won't make any config updates, |
| 331 |
as it's not a module config parameter. |
| 332 |
type: bool |
| 333 |
auto_publish_session: |
| 334 |
description: |
| 335 |
- Publish the current session if changes have been performed |
| 336 |
after task completes. |
| 337 |
type: bool |
| 338 |
version: |
| 339 |
description: |
| 340 |
- Version of checkpoint. If not given one, the latest version taken. |
| 341 |
type: str |
| 342 |
state: |
| 343 |
description: |
| 344 |
- The state the configuration should be left in |
| 345 |
- The state I(gathered) will get the module API configuration from the device |
| 346 |
and transform it into structured data in the format as per the module argspec |
| 347 |
and the value is returned in the I(gathered) key within the result. |
| 348 |
type: str |
| 349 |
choices: |
| 350 |
- merged |
| 351 |
- replaced |
| 352 |
- gathered |
| 353 |
- deleted |
| 354 |
""" |
| 355 |
|
| 356 |
EXAMPLES = """ |
| 357 |
|
| 358 |
# Using MERGED state |
| 359 |
# ------------------- |
| 360 |
|
| 361 |
- name: Merge MGMT Hosts config |
| 362 |
cp_mgmt_hosts: |
| 363 |
state: merged |
| 364 |
config: |
| 365 |
color: cyan |
| 366 |
ip_address: 192.0.2.1 |
| 367 |
name: New Host 1 |
| 368 |
auto_publish_session: true |
| 369 |
tags: |
| 370 |
- New Host |
| 371 |
round_trip: true |
| 372 |
|
| 373 |
# RUN output: |
| 374 |
# ----------- |
| 375 |
|
| 376 |
# mgmt_hosts: |
| 377 |
# after: |
| 378 |
# color: cyan |
| 379 |
# comments: '' |
| 380 |
# groups: [] |
| 381 |
# icon: Objects/host |
| 382 |
# interfaces: [] |
| 383 |
# ipv4-address: 192.0.2.1 |
| 384 |
# name: New Host 1 |
| 385 |
# nat_settings: {} |
| 386 |
# tags: |
| 387 |
# - New Host |
| 388 |
# before: {} |
| 389 |
|
| 390 |
# Using REPLACED state |
| 391 |
# -------------------- |
| 392 |
|
| 393 |
- name: Replace MGMT Host config |
| 394 |
cp_mgmt_hosts: |
| 395 |
state: replaced |
| 396 |
config: |
| 397 |
name: New Host 1 |
| 398 |
tags: |
| 399 |
- New Replaced Host |
| 400 |
color: aquamarine |
| 401 |
ip_address: 198.51.110.0 |
| 402 |
comments: REPLACED description |
| 403 |
ignore_warnings: true |
| 404 |
ignore_errors: false |
| 405 |
auto_publish_session: true |
| 406 |
round_trip: true |
| 407 |
|
| 408 |
# RUN output: |
| 409 |
# ----------- |
| 410 |
|
| 411 |
# mgmt_hosts: |
| 412 |
# after: |
| 413 |
# color: aquamarine |
| 414 |
# comments: REPLACED description |
| 415 |
# groups: [] |
| 416 |
# icon: Objects/host |
| 417 |
# interfaces: [] |
| 418 |
# ipv4-address: 198.51.110.0 |
| 419 |
# name: New Host 1 |
| 420 |
# nat_settings: {} |
| 421 |
# tags: |
| 422 |
# - New Replaced Host |
| 423 |
# before: |
| 424 |
# color: cyan |
| 425 |
# comments: '' |
| 426 |
# groups: [] |
| 427 |
# icon: Objects/host |
| 428 |
# interfaces: [] |
| 429 |
# ipv4-address: 192.0.2.1 |
| 430 |
# name: New Host 1 |
| 431 |
# nat_settings: {} |
| 432 |
# tags: |
| 433 |
# - New Host |
| 434 |
|
| 435 |
# Using GATHERED state |
| 436 |
# -------------------- |
| 437 |
|
| 438 |
# 1. With Round Trip set to True |
| 439 |
|
| 440 |
- name: Gather MGMT Host config by Name |
| 441 |
cp_mgmt_hosts: |
| 442 |
state: gathered |
| 443 |
config: |
| 444 |
name: New Host 1 |
| 445 |
|
| 446 |
# RUN output: |
| 447 |
# ----------- |
| 448 |
|
| 449 |
# gathered: |
| 450 |
# color: cyan |
| 451 |
# comments: REPLACED description |
| 452 |
# domain: SMC User |
| 453 |
# groups: [] |
| 454 |
# icon: Objects/host |
| 455 |
# interfaces: [] |
| 456 |
# ipv4-address: 192.0.2.1 |
| 457 |
# name: New Host 1 |
| 458 |
# nat_settings: {} |
| 459 |
# read-only: false |
| 460 |
# tags: |
| 461 |
# - New Host |
| 462 |
# uid: 63b868bb-d300-47f4-b97a-c465a56fe9c7 |
| 463 |
|
| 464 |
# 2. With Round Trip set to False which is the default behaviour |
| 465 |
|
| 466 |
- name: Gather MGMT Host config by Name |
| 467 |
cp_mgmt_hosts: |
| 468 |
state: gathered |
| 469 |
config: |
| 470 |
name: New Host 1 |
| 471 |
|
| 472 |
# RUN output: |
| 473 |
# ----------- |
| 474 |
|
| 475 |
# gathered: |
| 476 |
# color: cyan |
| 477 |
# comments: '' |
| 478 |
# domain: |
| 479 |
# domain-type: domain |
| 480 |
# name: SMC User |
| 481 |
# uid: 41e821a0-3720-11e3-aa6e-0800200c9fde |
| 482 |
# groups: [] |
| 483 |
# icon: Objects/host |
| 484 |
# interfaces: [] |
| 485 |
# ipv4-address: 192.0.2.1 |
| 486 |
# meta-info: |
| 487 |
# creation-time: |
| 488 |
# iso-8601: 2022-11-21T08:31+0000 |
| 489 |
# posix: 1669019480328 |
| 490 |
# creator: admin |
| 491 |
# last-modifier: admin |
| 492 |
# last-modify-time: |
| 493 |
# iso-8601: 2022-11-21T08:31+0000 |
| 494 |
# posix: 1669019480328 |
| 495 |
# lock: unlocked |
| 496 |
# validation-state: ok |
| 497 |
# name: New Host 1 |
| 498 |
# nat_settings: {} |
| 499 |
# read-only: false |
| 500 |
# tags: |
| 501 |
# - domain: |
| 502 |
# domain-type: domain |
| 503 |
# name: SMC User |
| 504 |
# uid: 41e821a0-3720-11e3-aa6e-0800200c9fde |
| 505 |
# name: New Host |
| 506 |
# type: tag |
| 507 |
# uid: 94d53896-3cee-4e1f-a83b-3abac80bf512 |
| 508 |
# type: host |
| 509 |
# uid: 8f23a44b-d9d2-4242-8a9e-2a4cbb6723ff |
| 510 |
|
| 511 |
# 3. Gather ALL threat-layer config with DESC order filter |
| 512 |
|
| 513 |
- name: Gather All hosts on the MGMT instance |
| 514 |
cp_mgmt_hosts: |
| 515 |
config: |
| 516 |
details_level: full |
| 517 |
state: gathered |
| 518 |
|
| 519 |
# RUN output: |
| 520 |
# ----------- |
| 521 |
|
| 522 |
# gathered: |
| 523 |
# - domain: |
| 524 |
# domain-type: domain |
| 525 |
# name: SMC User |
| 526 |
# uid: 41e821a0-3720-11e3-aa6e-0800200c9fde |
| 527 |
# ipv4-address: 192.0.2.1 |
| 528 |
# name: New Host 1 |
| 529 |
# type: host |
| 530 |
# uid: 8f23a44b-d9d2-4242-8a9e-2a4cbb6723ff |
| 531 |
|
| 532 |
# Using DELETED state |
| 533 |
# ------------------- |
| 534 |
|
| 535 |
- name: Delete MGMT Host config by Name |
| 536 |
cp_mgmt_hosts: |
| 537 |
state: deleted |
| 538 |
config: |
| 539 |
name: New Host 1 |
| 540 |
round_trip: true |
| 541 |
|
| 542 |
# RUN output: |
| 543 |
# ----------- |
| 544 |
|
| 545 |
# mgmt_hosts: |
| 546 |
# after: {} |
| 547 |
# before: |
| 548 |
# color: cyan |
| 549 |
# comments: REPLACED description |
| 550 |
# groups: [] |
| 551 |
# icon: Objects/host |
| 552 |
# interfaces: [] |
| 553 |
# ipv4-address: 192.0.2.1 |
| 554 |
# name: New Host 1 |
| 555 |
# nat_settings: {} |
| 556 |
# tags: |
| 557 |
# - New Host |
| 558 |
""" |
| 559 |
|
| 560 |
RETURN = """ |
| 561 |
before: |
| 562 |
description: The configuration prior to the module execution. |
| 563 |
returned: when state is I(merged), I(replaced), I(deleted) |
| 564 |
type: dict |
| 565 |
sample: > |
| 566 |
This output will always be in the same format as the |
| 567 |
module argspec. |
| 568 |
after: |
| 569 |
description: The resulting configuration after module execution. |
| 570 |
returned: when changed |
| 571 |
type: dict |
| 572 |
sample: > |
| 573 |
This output will always be in the same format as the |
| 574 |
module argspec. |
| 575 |
gathered: |
| 576 |
description: Facts about the network resource gathered from the remote device as structured data. |
| 577 |
returned: when state is I(gathered) |
| 578 |
type: dict |
| 579 |
sample: > |
| 580 |
This output will always be in the same format as the |
| 581 |
module argspec. |
| 582 |
""" |