How to Import a Kibana Dashboard with Ansible?

We are upgrading from 7.9.3 to 7.17.8. I see that the method to import Kibana dashboards has changed. I can successfully import a dashboard using curl and using Postman.

curl -k -u <username>:<password> -X POST -H 'kbn-xsrf: true' --form file=@roles/kibana/files/database-monitor.ndjson

We normally install our dashboards using Ansible and it worked great using the old /api/kibana/dashboards/import URL. However, I can't figure out how to get Ansible to work correctly to install a dashboard with this new API.

- name: Load Kibana dashboards
    url: "{{kibana_url}}/api/saved_objects/_import?overwrite=true"
    method: POST
      kbn-version: "{{es_stack_version}}"
      kbn-xsrf: true
    body-format: raw
    user: "{{}}"
    password: "{{user.password}}"
    force_basic_auth: yes
    validate_certs: no
    body: "file=@{{item}}"
    - database-monitor.ndjson
  run_once: True

When I try this I get:
msg: 'Status code was 415 and not [200]: HTTP Error 415: Unsupported Media Type'

Ansible doesn't support it. We just use a shell or command module with the same curl command u posted.

1 Like

Here's the solution as implemented:

- name: Load Kibana dashboards via shell
  shell: "curl -k -u {{}}:{{user.password}} \
    -X POST {{kibana_url}}/api/saved_objects/_import?overwrite=true -H 'kbn-xsrf: true' \
    --form file=@{{playbook_dir}}/<path>/{{item}}"
    warn: False
    - database-monitor.ndjson
  run_once: True

Set "warn" to false to keep ansible from displaying a suggestion to use the uri command instead.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.