| 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_securityconsole_install_device |
| 15 |
short_description: Securityconsole install device |
| 16 |
version_added: "1.0.0" |
| 17 |
extends_documentation_fragment: |
| 18 |
- fortinet.fortimanager.general |
| 19 |
options: |
| 20 |
securityconsole_install_device: |
| 21 |
description: The top level parameters set. |
| 22 |
required: false |
| 23 |
type: dict |
| 24 |
suboptions: |
| 25 |
adom: |
| 26 |
type: str |
| 27 |
description: Source ADOM name. |
| 28 |
dev_rev_comments: |
| 29 |
type: str |
| 30 |
description: Dev rev comments. |
| 31 |
flags: |
| 32 |
type: list |
| 33 |
elements: str |
| 34 |
description: |
| 35 |
- preview - Generate preview cache only. |
| 36 |
- auto_lock_ws - Automatically lock and unlock workspace when performing security console task. |
| 37 |
choices: ['none', 'preview', 'auto_lock_ws'] |
| 38 |
scope: |
| 39 |
type: list |
| 40 |
elements: dict |
| 41 |
description: Scope. |
| 42 |
suboptions: |
| 43 |
name: |
| 44 |
type: str |
| 45 |
description: Name. |
| 46 |
vdom: |
| 47 |
type: str |
| 48 |
description: Vdom. |
| 49 |
''' |
| 50 |
|
| 51 |
EXAMPLES = ''' |
| 52 |
- name: Commit config to real device |
| 53 |
hosts: fortimanagers |
| 54 |
gather_facts: false |
| 55 |
connection: httpapi |
| 56 |
vars: |
| 57 |
ansible_httpapi_use_ssl: true |
| 58 |
ansible_httpapi_validate_certs: false |
| 59 |
ansible_httpapi_port: 443 |
| 60 |
device_adom: "root" |
| 61 |
script_name: "FooScript" |
| 62 |
device_name: "CustomHostName" |
| 63 |
device_vdom: "root" |
| 64 |
tasks: |
| 65 |
- name: Invoke the task |
| 66 |
fortinet.fortimanager.fmgr_securityconsole_install_device: |
| 67 |
securityconsole_install_device: |
| 68 |
adom: "{{ device_adom }}" |
| 69 |
scope: |
| 70 |
- name: "{{ device_name }}" |
| 71 |
vdom: "{{ device_vdom }}" |
| 72 |
register: installing_task |
| 73 |
- name: Inspect the Task Status |
| 74 |
fortinet.fortimanager.fmgr_fact: |
| 75 |
facts: |
| 76 |
selector: "task_task" |
| 77 |
params: |
| 78 |
task: "{{ installing_task.meta.response_data.task }}" |
| 79 |
register: taskinfo |
| 80 |
until: taskinfo.meta.response_data.percent == 100 |
| 81 |
retries: 30 |
| 82 |
delay: 3 |
| 83 |
failed_when: taskinfo.meta.response_data.state == 'error' |
| 84 |
|
| 85 |
- name: Example playbook |
| 86 |
hosts: fortimanagers |
| 87 |
gather_facts: false |
| 88 |
connection: httpapi |
| 89 |
vars: |
| 90 |
ansible_httpapi_use_ssl: true |
| 91 |
ansible_httpapi_validate_certs: false |
| 92 |
ansible_httpapi_port: 443 |
| 93 |
tasks: |
| 94 |
- name: Run fmgr_securityconsole_install_device |
| 95 |
fortinet.fortimanager.fmgr_securityconsole_install_device: |
| 96 |
bypass_validation: false |
| 97 |
securityconsole_install_device: |
| 98 |
adom: ansible |
| 99 |
dev_rev_comments: ansible-comment |
| 100 |
flags: |
| 101 |
- none |
| 102 |
- preview |
| 103 |
- auto_lock_ws |
| 104 |
scope: |
| 105 |
- name: Ansible-test |
| 106 |
vdom: root |
| 107 |
''' |
| 108 |
|
| 109 |
RETURN = ''' |
| 110 |
meta: |
| 111 |
description: The result of the request. |
| 112 |
type: dict |
| 113 |
returned: always |
| 114 |
contains: |
| 115 |
request_url: |
| 116 |
description: The full url requested. |
| 117 |
returned: always |
| 118 |
type: str |
| 119 |
sample: /sys/login/user |
| 120 |
response_code: |
| 121 |
description: The status of api request. |
| 122 |
returned: always |
| 123 |
type: int |
| 124 |
sample: 0 |
| 125 |
response_data: |
| 126 |
description: The api response. |
| 127 |
type: list |
| 128 |
returned: always |
| 129 |
response_message: |
| 130 |
description: The descriptive message of the api response. |
| 131 |
type: str |
| 132 |
returned: always |
| 133 |
sample: OK. |
| 134 |
system_information: |
| 135 |
description: The information of the target system. |
| 136 |
type: dict |
| 137 |
returned: always |
| 138 |
rc: |
| 139 |
description: The status the request. |
| 140 |
type: int |
| 141 |
returned: always |
| 142 |
sample: 0 |
| 143 |
version_check_warning: |
| 144 |
description: Warning if the parameters used in the playbook are not supported by the current FortiManager version. |
| 145 |
type: list |
| 146 |
returned: complex |
| 147 |
''' |
| 148 |
from ansible.module_utils.basic import AnsibleModule |
| 149 |
from ansible.module_utils.connection import Connection |
| 150 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass |
| 151 |
from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec |
| 152 |
|
| 153 |
|
| 154 |
def main(): |
| 155 |
urls_list = [ |
| 156 |
'/securityconsole/install/device' |
| 157 |
] |
| 158 |
module_arg_spec = { |
| 159 |
'securityconsole_install_device': { |
| 160 |
'type': 'dict', 'v_range': [['6.0.0', '']], |
| 161 |
'options': { |
| 162 |
'adom': {'type': 'str'}, |
| 163 |
'dev_rev_comments': {'type': 'str'}, |
| 164 |
'flags': {'type': 'list', 'choices': ['none', 'preview', 'auto_lock_ws'], 'elements': 'str'}, |
| 165 |
'scope': {'type': 'list', 'options': {'name': {'type': 'str'}, 'vdom': {'type': 'str'}}, 'elements': 'dict'} |
| 166 |
} |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
module_option_spec = get_module_arg_spec('exec') |
| 171 |
module_arg_spec.update(module_option_spec) |
| 172 |
check_galaxy_version(module_arg_spec) |
| 173 |
module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'securityconsole_install_device'), |
| 174 |
supports_check_mode=True) |
| 175 |
if not module._socket_path: |
| 176 |
module.fail_json(msg='MUST RUN IN HTTPAPI MODE') |
| 177 |
connection = Connection(module._socket_path) |
| 178 |
fmgr = NAPIManager('exec', module_arg_spec, urls_list, |
| 179 |
None, 'data', module, connection) |
| 180 |
fmgr.process_exec() |
| 181 |
module.exit_json(meta=module.params) |
| 182 |
|
| 183 |
|
| 184 |
if __name__ == '__main__': |
| 185 |
main() |