---
- hosts: restore.group
gather_facts: false
tasks:
- name: Login
uri:
url: https://{{ ansible_host }}/logincheck
validate_certs: no
method : "POST"
body_format: "form-urlencoded"
url_username: "{{ ansible_user }}"
url_password: "{{ ansible_password }}"
body:
- [ username, "{{ ansible_user }}" ]
- [ secretkey, "{{ ansible_password }}" ]
- [ ajax, "1" ]
register: http_response
- name: GET Config Restore
uri:
url: https://{{ ansible_host }}/api/v2/{{ api_type }}/{{ api_path }}/{{ api_name }}/restore?scope=global
validate_certs: no
force_basic_auth: yes
method: "POST"
headers:
Cookie: "{{ http_response.set_cookie }}"
return_content: yes
body: "{{ lookup('file','/home/ansible/restore_config.json') }}"
body_format: json
remote_src: yes
〇debug
{
"content": "{\n \"path\":\"system\",\n \"name\":\"config\",\n \"action\":\"restore\",\n \"serial\":\"FGT***\",\n \"version\":\"v7.0.0\",\n \"build\":66,\n \"status\":\"error\",\n \"http_status\":424\n}",
"redirected": false,
"url": "https://*.*.*.*/api/v2/monitor/system/config/restore?scope=global",
"status": 424,
"date": "Tue, 27 Jul 2021 08:11:17 GMT",
"set_cookie": "***=\"***\"; path=/; secure; HttpOnly; SameSite=Strict",
"x_frame_options": "SAMEORIGIN",
"content_security_policy": "frame-ancestors 'self'",
"x_xss_protection": "1; mode=block",
"cache_control": "no-cache, must-revalidate",
"content_length": "170",
"content_type": "application/json",
"connection": "close",
"msg": "Status code was 424 and not [200]: HTTP Error 424: Failed Dependency",
"elapsed": 0,
"changed": false,
"json": {
"path": "system",
"name": "config",
"action": "restore",
"serial": "FGT*******",
"version": "v7.0.0",
"build": 66,
"status": "error",
"http_status": 424
},
"invocation": {
"module_args": {
"url": "https://*.*.*.*/api/v2/monitor/system/config/restore?scope=global",
"validate_certs": false,
"force_basic_auth": true,
"method": "POST",
"headers": {
"Cookie": "APSCOOKIE_***=\"***\"; path=/; secure; HttpOnly; SameSite=Strict, ccsrftoken_***=\"***\"; path=/; secure; SameSite=Strict, ccsrftoken=\"***\"; path=/; secure; SameSite=Strict",
"Content-Type": "application/json"
},
"return_content": true,
"body": "***",
"remote_src": "True",
"force": false,
"http_agent": "ansible-httpget",
"use_proxy": true,
"follow_redirects": "safe",
"status_code": [
200
],
"timeout": 30,
"follow": false,
"url_username": null,
"url_password": null,
"client_cert": null,
"client_key": null,
"dest": null,
"src": null,
"creates": null,
"removes": null,
"unix_socket": null,
"mode": null,
"owner": null,
"group": null,
"seuser": null,
"serole": null,
"selevel": null,
"setype": null,
"attributes": null,
"content": null,
"backup": null,
"regexp": null,
"delimiter": null,
"directory_mode": null,
"unsafe_writes": null
}
},
"warnings": [
"The value True (type bool) in a string field was converted to 'True' (type string). If this does not look like what you expect, quote the entire value to ensure it does not change."
],
"_ansible_no_log": false
}