# How to Import a Kibana Dashboard with Ansible?

**URL:** <https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487>\
**Category:** Kibana\
**Created:** [February 1, 2023, 10:50pm UTC](https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487 "2023-02-01T22:50:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![silentfilm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silentfilm/32/44348_2.png) [@silentfilm](https://discuss.elastic.co/u/silentfilm)\
**Post date:** [February 1, 2023, 10:50pm UTC](https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487/1 "2023-02-01T22:50:02Z")

</div>

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.

```auto
curl -k -u <username>:<password> -X POST https://aln-nbadev4.labs.netscout.com:5601/api/saved_objects/_import?overwrite=true -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.

```auto
- name: Load Kibana dashboards
  uri:
    url: "{{kibana_url}}/api/saved_objects/_import?overwrite=true"
    method: POST
    headers:
      kbn-version: "{{es_stack_version}}"
      kbn-xsrf: true
    body-format: raw
    user: "{{user.name}}"
    password: "{{user.password}}"
    force_basic_auth: yes
    validate_certs: no
    body: "file=@{{item}}"
  with_items:
    - 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'

---

<div class="post-metadata">

**Author:** ![legoguy1000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/legoguy1000/32/54301_2.png) [@legoguy1000](https://discuss.elastic.co/u/legoguy1000)\
**Post date:** [February 2, 2023, 2:35am UTC](https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487/2 "2023-02-02T02:35:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![silentfilm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/silentfilm/32/44348_2.png) [@silentfilm](https://discuss.elastic.co/u/silentfilm)\
**Post date:** [February 2, 2023, 5:56pm UTC](https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487/3 "2023-02-02T17:56:33Z")

</div>

Here's the solution as implemented:

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

```

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 2, 2023, 5:56pm UTC](https://discuss.elastic.co/t/how-to-import-a-kibana-dashboard-with-ansible/324487/4 "2023-03-02T17:56:52Z")

</div>

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