| 1 |
|
| 2 |
from __future__ import absolute_import, division, print_function |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'status': ['preview'], |
| 9 |
'supported_by': 'community', |
| 10 |
'metadata_version': '1.1'} |
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: fmgr_webproxy_profile |
| 15 |
short_description: Configure web proxy profiles. |
| 16 |
version_added: "1.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
- fortinet.fortimanager.general.full_crud |
| 20 |
options: |
| 21 |
revision_note: |
| 22 |
description: The change note that can be specified when an object is created or updated. |
| 23 |
type: str |
| 24 |
adom: |
| 25 |
description: The parameter (adom) in requested url. |
| 26 |
type: str |
| 27 |
required: true |
| 28 |
webproxy_profile: |
| 29 |
description: The top level parameters set. |
| 30 |
required: false |
| 31 |
type: dict |
| 32 |
suboptions: |
| 33 |
header_client_ip: |
| 34 |
aliases: ['header-client-ip'] |
| 35 |
type: str |
| 36 |
description: Action to take on the HTTP client-IP header in forwarded requests |
| 37 |
choices: ['pass', 'add', 'remove'] |
| 38 |
header_front_end_https: |
| 39 |
aliases: ['header-front-end-https'] |
| 40 |
type: str |
| 41 |
description: Action to take on the HTTP front-end-HTTPS header in forwarded requests |
| 42 |
choices: ['pass', 'add', 'remove'] |
| 43 |
header_via_request: |
| 44 |
aliases: ['header-via-request'] |
| 45 |
type: str |
| 46 |
description: Action to take on the HTTP via header in forwarded requests |
| 47 |
choices: ['pass', 'add', 'remove'] |
| 48 |
header_via_response: |
| 49 |
aliases: ['header-via-response'] |
| 50 |
type: str |
| 51 |
description: Action to take on the HTTP via header in forwarded responses |
| 52 |
choices: ['pass', 'add', 'remove'] |
| 53 |
header_x_authenticated_groups: |
| 54 |
aliases: ['header-x-authenticated-groups'] |
| 55 |
type: str |
| 56 |
description: Action to take on the HTTP x-authenticated-groups header in forwarded requests |
| 57 |
choices: ['pass', 'add', 'remove'] |
| 58 |
header_x_authenticated_user: |
| 59 |
aliases: ['header-x-authenticated-user'] |
| 60 |
type: str |
| 61 |
description: Action to take on the HTTP x-authenticated-user header in forwarded requests |
| 62 |
choices: ['pass', 'add', 'remove'] |
| 63 |
header_x_forwarded_for: |
| 64 |
aliases: ['header-x-forwarded-for'] |
| 65 |
type: str |
| 66 |
description: Action to take on the HTTP x-forwarded-for header in forwarded requests |
| 67 |
choices: ['pass', 'add', 'remove'] |
| 68 |
headers: |
| 69 |
type: list |
| 70 |
elements: dict |
| 71 |
description: Headers. |
| 72 |
suboptions: |
| 73 |
action: |
| 74 |
type: str |
| 75 |
description: Action when HTTP the header forwarded. |
| 76 |
choices: ['add-to-request', 'add-to-response', 'remove-from-request', |
| 77 |
'remove-from-response', 'monitor-request', 'monitor-response'] |
| 78 |
content: |
| 79 |
type: str |
| 80 |
description: HTTP headers content. |
| 81 |
id: |
| 82 |
type: int |
| 83 |
description: HTTP forwarded header id. |
| 84 |
name: |
| 85 |
type: str |
| 86 |
description: HTTP forwarded header name. |
| 87 |
add_option: |
| 88 |
aliases: ['add-option'] |
| 89 |
type: str |
| 90 |
description: Configure options to append content to existing HTTP header or add new HTTP header. |
| 91 |
choices: ['append', 'new-on-not-found', 'new', 'replace', |
| 92 |
'replace-when-match'] |
| 93 |
base64_encoding: |
| 94 |
aliases: ['base64-encoding'] |
| 95 |
type: str |
| 96 |
description: Enable/disable use of base64 encoding of HTTP content. |
| 97 |
choices: ['disable', 'enable'] |
| 98 |
dstaddr: |
| 99 |
type: raw |
| 100 |
description: (list or str) Destination address and address group names. |
| 101 |
dstaddr6: |
| 102 |
type: raw |
| 103 |
description: (list or str) Destination address and address group names |
| 104 |
protocol: |
| 105 |
type: list |
| 106 |
elements: str |
| 107 |
description: Configure protocol |
| 108 |
choices: ['https', 'http'] |
| 109 |
log_header_change: |
| 110 |
aliases: ['log-header-change'] |
| 111 |
type: str |
| 112 |
description: Enable/disable logging HTTP header changes. |
| 113 |
choices: ['disable', 'enable'] |
| 114 |
name: |
| 115 |
type: str |
| 116 |
description: Profile name. |
| 117 |
required: true |
| 118 |
strip_encoding: |
| 119 |
aliases: ['strip-encoding'] |
| 120 |
type: str |
| 121 |
description: Enable/disable stripping unsupported encoding from the request header. |
| 122 |
choices: ['disable', 'enable'] |
| 123 |
header_x_forwarded_client_cert: |
| 124 |
aliases: ['header-x-forwarded-client-cert'] |
| 125 |
type: str |
| 126 |
description: Action to take on the HTTP x-forwarded-client-cert header in forwarded requests |
| 127 |
choices: ['pass', 'add', 'remove'] |
| 128 |
max_cache_object_size: |
| 129 |
aliases: ['max-cache-object-size'] |
| 130 |
type: int |
| 131 |
description: Max cache object size. |
| 132 |
header_client_cert: |
| 133 |
aliases: ['header-client-cert'] |
| 134 |
type: str |
| 135 |
description: Action to take on the HTTP Client-Cert/Client-Cert-Chain headers in forwarded responses |
| 136 |
choices: ['pass', 'add', 'remove'] |
| 137 |
''' |
| 138 |
|
| 139 |
EXAMPLES = ''' |
| 140 |
- name: Example playbook (generated based on argument schema) |
| 141 |
hosts: fortimanagers |
| 142 |
connection: httpapi |
| 143 |
gather_facts: false |
| 144 |
tasks: |
| 145 |
- name: Configure web proxy profiles. |
| 146 |
fortinet.fortimanager.fmgr_webproxy_profile: |
| 147 |
# workspace_locking_adom: <global or your adom name> |
| 148 |
adom: <your own value> |
| 149 |
state: present # <value in [present, absent]> |
| 150 |
webproxy_profile: |
| 151 |
name: "your value" # Required variable, string |
| 152 |
# header_client_ip: <value in [pass, add, remove]> |
| 153 |
# header_front_end_https: <value in [pass, add, remove]> |
| 154 |
# header_via_request: <value in [pass, add, remove]> |
| 155 |
# header_via_response: <value in [pass, add, remove]> |
| 156 |
# header_x_authenticated_groups: <value in [pass, add, remove]> |
| 157 |
# header_x_authenticated_user: <value in [pass, add, remove]> |
| 158 |
# header_x_forwarded_for: <value in [pass, add, remove]> |
| 159 |
# headers: |
| 160 |
# - action: <value in [add-to-request, add-to-response, remove-from-request, ...]> |
| 161 |
# content: <string> |
| 162 |
# id: <integer> |
| 163 |
# name: <string> |
| 164 |
# add_option: <value in [append, new-on-not-found, new, ...]> |
| 165 |
# base64_encoding: <value in [disable, enable]> |
| 166 |
# dstaddr: <list or string> |
| 167 |
# dstaddr6: <list or string> |
| 168 |
# protocol: ["https", "http"] |
| 169 |
# log_header_change: <value in [disable, enable]> |
| 170 |
# strip_encoding: <value in [disable, enable]> |
| 171 |
# header_x_forwarded_client_cert: <value in [pass, add, remove]> |
| 172 |
# max_cache_object_size: <integer> |
| 173 |
# header_client_cert: <value in [pass, add, remove]> |
| 174 |
''' |
| 175 |
|
| 176 |
RETURN = ''' |
| 177 |
meta: |
| 178 |
description: The result of the request. |
| 179 |
type: dict |
| 180 |
returned: always |
| 181 |
contains: |
| 182 |
request_url: |
| 183 |
description: The full url requested. |
| 184 |
returned: always |
| 185 |
type: str |
| 186 |
sample: /sys/login/user |
| 187 |
response_code: |
| 188 |
description: The status of api request. |
| 189 |
returned: always |
| 190 |
type: int |
| 191 |
sample: 0 |
| 192 |
response_data: |
| 193 |
description: The api response. |
| 194 |
type: list |
| 195 |
returned: always |
| 196 |
response_message: |
| 197 |
description: The descriptive message of the api response. |
| 198 |
type: str |
| 199 |
returned: always |
| 200 |
sample: OK. |
| 201 |
system_information: |
| 202 |
description: The information of the target system. |
| 203 |
type: dict |
| 204 |
returned: always |
| 205 |
rc: |
| 206 |
description: The status the request. |
| 207 |
type: int |
| 208 |
returned: always |
| 209 |
sample: 0 |
| 210 |
version_check_warning: |
| 211 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 212 |
type: list |
| 213 |
returned: complex |
| 214 |
''' |
| 215 |
from ansible.module_utils.basic import AnsibleModule |
| 216 |
from ansible.module_utils.connection import Connection |
| 217 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 218 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 219 |
|
| 220 |
|
| 221 |
def main(): |
| 222 |
urls_list = [ |
| 223 |
'/pm/config/adom/{adom}/obj/web-proxy/profile', |
| 224 |
'/pm/config/global/obj/web-proxy/profile' |
| 225 |
] |
| 226 |
module_arg_spec = { |
| 227 |
'adom': {'required': True, 'type': 'str'}, |
| 228 |
'revision_note': {'type': 'str'}, |
| 229 |
'webproxy_profile': { |
| 230 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 231 |
'options': { |
| 232 |
'header-client-ip': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 233 |
'header-front-end-https': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 234 |
'header-via-request': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 235 |
'header-via-response': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 236 |
'header-x-authenticated-groups': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 237 |
'header-x-authenticated-user': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 238 |
'header-x-forwarded-for': {'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 239 |
'headers': { |
| 240 |
'type': 'list', |
| 241 |
'options': { |
| 242 |
'action': { |
| 243 |
'choices': [ |
| 244 |
'add-to-request', 'add-to-response', 'remove-from-request', 'remove-from-response', 'monitor-request', |
| 245 |
'monitor-response' |
| 246 |
], |
| 247 |
'type': 'str' |
| 248 |
}, |
| 249 |
'content': {'type': 'str'}, |
| 250 |
'id': {'type': 'int'}, |
| 251 |
'name': {'type': 'str'}, |
| 252 |
'add-option': { |
| 253 |
'v_range': [['6.2.0', '']], |
| 254 |
'choices': ['append', 'new-on-not-found', 'new', 'replace', 'replace-when-match'], |
| 255 |
'type': 'str' |
| 256 |
}, |
| 257 |
'base64-encoding': {'v_range': [['6.2.0', '']], 'choices': ['disable', 'enable'], 'type': 'str'}, |
| 258 |
'dstaddr': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 259 |
'dstaddr6': {'v_range': [['6.2.0', '']], 'type': 'raw'}, |
| 260 |
'protocol': {'v_range': [['6.2.0', '']], 'type': 'list', 'choices': ['https', 'http'], 'elements': 'str'} |
| 261 |
}, |
| 262 |
'elements': 'dict' |
| 263 |
}, |
| 264 |
'log-header-change': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 265 |
'name': {'required': True, 'type': 'str'}, |
| 266 |
'strip-encoding': {'choices': ['disable', 'enable'], 'type': 'str'}, |
| 267 |
'header-x-forwarded-client-cert': {'v_range': [['7.0.1', '']], 'choices': ['pass', 'add', 'remove'], 'type': 'str'}, |
| 268 |
'max-cache-object-size': {'v_range': [['7.4.8', '7.4.10'], ['7.6.4', '']], 'type': 'int'}, |
| 269 |
'header-client-cert': {'v_range': [['7.6.5', '']], 'choices': ['pass', 'add', 'remove'], 'type': 'str'} |
| 270 |
} |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
module_option_spec = get_module_arg_spec('full crud') |
| 275 |
module_arg_spec.update(module_option_spec) |
| 276 |
check_galaxy_version(module_arg_spec) |
| 277 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'webproxy_profile'), |
| 278 |
supports_check_mode=True) |
| 279 |
if not module._socket_path: |
| 280 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 281 |
connection = Connection(module._socket_path) |
| 282 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 283 |
'name', 'data', module, connection) |
| 284 |
fmgr.process_crud() |
| 285 |
module.exit_json(meta=module.params) |
| 286 |
|
| 287 |
|
| 288 |
if __name__ == '__main__': |
| 289 |
main() |