| 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_firewall_gtp_apn |
| 15 |
short_description: APN. |
| 16 |
version_added: "2.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 |
gtp: |
| 29 |
description: The parameter (gtp) in requested url. |
| 30 |
type: str |
| 31 |
required: true |
| 32 |
firewall_gtp_apn: |
| 33 |
description: The top level parameters set. |
| 34 |
required: false |
| 35 |
type: dict |
| 36 |
suboptions: |
| 37 |
action: |
| 38 |
type: str |
| 39 |
description: Action. |
| 40 |
choices: ['allow', 'deny'] |
| 41 |
apnmember: |
| 42 |
type: raw |
| 43 |
description: (list or str) APN member. |
| 44 |
id: |
| 45 |
type: int |
| 46 |
description: ID. |
| 47 |
required: true |
| 48 |
selection_mode: |
| 49 |
aliases: ['selection-mode'] |
| 50 |
type: list |
| 51 |
elements: str |
| 52 |
description: APN selection mode. |
| 53 |
choices: ['ms', 'net', 'vrf'] |
| 54 |
''' |
| 55 |
|
| 56 |
EXAMPLES = ''' |
| 57 |
- name: Example playbook |
| 58 |
hosts: fortimanagers |
| 59 |
gather_facts: false |
| 60 |
connection: httpapi |
| 61 |
vars: |
| 62 |
ansible_httpapi_use_ssl: true |
| 63 |
ansible_httpapi_validate_certs: false |
| 64 |
ansible_httpapi_port: 443 |
| 65 |
tasks: |
| 66 |
- name: APN. |
| 67 |
fortinet.fortimanager.fmgr_firewall_gtp_apn: |
| 68 |
bypass_validation: false |
| 69 |
adom: FortiCarrier # FortiCarrier only object, need a FortiCarrier adom |
| 70 |
gtp: "ansible-test" # name |
| 71 |
state: present |
| 72 |
firewall_gtp_apn: |
| 73 |
action: allow # <value in [allow, deny]> |
| 74 |
apnmember: "ansible-test1" # need a valid APN member |
| 75 |
id: 3 |
| 76 |
selection_mode: |
| 77 |
- ms |
| 78 |
- net |
| 79 |
- vrf |
| 80 |
|
| 81 |
- name: Gathering fortimanager facts |
| 82 |
hosts: fortimanagers |
| 83 |
gather_facts: false |
| 84 |
connection: httpapi |
| 85 |
vars: |
| 86 |
ansible_httpapi_use_ssl: true |
| 87 |
ansible_httpapi_validate_certs: false |
| 88 |
ansible_httpapi_port: 443 |
| 89 |
tasks: |
| 90 |
- name: Retrieve all the APNs |
| 91 |
fortinet.fortimanager.fmgr_fact: |
| 92 |
facts: |
| 93 |
selector: "firewall_gtp_apn" |
| 94 |
params: |
| 95 |
adom: "FortiCarrier" # FortiCarrier only object, need a FortiCarrier adom |
| 96 |
gtp: "ansible-test" # name |
| 97 |
apn: "your_value" |
| 98 |
''' |
| 99 |
|
| 100 |
RETURN = ''' |
| 101 |
meta: |
| 102 |
description: The result of the request. |
| 103 |
type: dict |
| 104 |
returned: always |
| 105 |
contains: |
| 106 |
request_url: |
| 107 |
description: The full url requested. |
| 108 |
returned: always |
| 109 |
type: str |
| 110 |
sample: /sys/login/user |
| 111 |
response_code: |
| 112 |
description: The status of api request. |
| 113 |
returned: always |
| 114 |
type: int |
| 115 |
sample: 0 |
| 116 |
response_data: |
| 117 |
description: The api response. |
| 118 |
type: list |
| 119 |
returned: always |
| 120 |
response_message: |
| 121 |
description: The descriptive message of the api response. |
| 122 |
type: str |
| 123 |
returned: always |
| 124 |
sample: OK. |
| 125 |
system_information: |
| 126 |
description: The information of the target system. |
| 127 |
type: dict |
| 128 |
returned: always |
| 129 |
rc: |
| 130 |
description: The status the request. |
| 131 |
type: int |
| 132 |
returned: always |
| 133 |
sample: 0 |
| 134 |
version_check_warning: |
| 135 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 136 |
type: list |
| 137 |
returned: complex |
| 138 |
''' |
| 139 |
from ansible.module_utils.basic import AnsibleModule |
| 140 |
from ansible.module_utils.connection import Connection |
| 141 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 142 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 143 |
|
| 144 |
|
| 145 |
def main(): |
| 146 |
urls_list = [ |
| 147 |
'/pm/config/adom/{adom}/obj/firewall/gtp/{gtp}/apn', |
| 148 |
'/pm/config/global/obj/firewall/gtp/{gtp}/apn' |
| 149 |
] |
| 150 |
module_arg_spec = { |
| 151 |
'adom': {'required': True, 'type': 'str'}, |
| 152 |
'gtp': {'required': True, 'type': 'str'}, |
| 153 |
'revision_note': {'type': 'str'}, |
| 154 |
'firewall_gtp_apn': { |
| 155 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 156 |
'options': { |
| 157 |
'action': {'choices': ['allow', 'deny'], 'type': 'str'}, |
| 158 |
'apnmember': {'type': 'raw'}, |
| 159 |
'id': {'required': True, 'type': 'int'}, |
| 160 |
'selection-mode': {'type': 'list', 'choices': ['ms', 'net', 'vrf'], 'elements': 'str'} |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
module_option_spec = get_module_arg_spec('full crud') |
| 166 |
module_arg_spec.update(module_option_spec) |
| 167 |
check_galaxy_version(module_arg_spec) |
| 168 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'firewall_gtp_apn'), |
| 169 |
supports_check_mode=True) |
| 170 |
if not module._socket_path: |
| 171 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 172 |
connection = Connection(module._socket_path) |
| 173 |
fmgr = NAPIManager('full crud', module_arg_spec, urls_list, |
| 174 |
'id', 'data', module, connection) |
| 175 |
fmgr.process_crud() |
| 176 |
module.exit_json(meta=module.params) |
| 177 |
|
| 178 |
|
| 179 |
if __name__ == '__main__': |
| 180 |
main() |