I want to restore the config backed up by fortigate using ansible

335 views
Skip to first unread message

room rabosan

unread,
Jul 27, 2021, 6:14:39 AM7/27/21
to Ansible Project
Hello!!
I want to restore the config backed up by fortigate using ansible
I'm using the Monitor API, which is supported by the REST API.
→Restore / Backup config with Monitor API
The Backup is complete, but I can't control the Restore well.
→HTTP Error 424:Failed Dependency
Could you please help me to solve it?
The playbook and debug statements are listed below.

〇 version
Ansible: 2.9.7
Forigate 60F: v7.0.0

〇 Executable file: restore_playbook.yml
Variables are defined in: group_vars
---
- 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
}








Stefan Hornburg (Racke)

unread,
Jul 27, 2021, 6:23:06 AM7/27/21
to ansible...@googlegroups.com
On 27/07/2021 12:14, room rabosan wrote:
> Hello!!
> I want to restore the config backed up by fortigate using ansible
> I'm using the Monitor API, which is supported by the REST API.
> →Restore / Backup config with Monitor API
> The Backup is complete, but I can't control the Restore well.
> →HTTP Error 424:Failed Dependency
> Could you please help me to solve it?
> The playbook and debug statements are listed below.
Try to find out why the API response used that HTTP error code.
You might get more help with the Fortigate community than here.

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d6defb11-cadc-4a0e-b3cc-686bf5efe84en%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/d6defb11-cadc-4a0e-b3cc-686bf5efe84en%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.

Reply all
Reply to author
Forward
0 new messages