Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with idempotent playbook , overwrite and datasources #196

Open
adamsipo opened this issue Nov 24, 2021 · 0 comments
Open

Problem with idempotent playbook , overwrite and datasources #196

adamsipo opened this issue Nov 24, 2021 · 0 comments

Comments

@adamsipo
Copy link

Hi guys

If i would like to import dashboard without changes i have to set overwrite on true , and its problem because i still change dashboards, is it possible to set only status --> present and then overwrite only if dashboard has been changed.

overwrite boolean | Choices:no ←yes | Override existing dashboard when state is present.

Datasource , if i upload datasource to main org. and datasource exist nothing change (its correct) when i create second org.
1.Main Org
2.Public Org --> if i run playbook on public org datasources are changed (its idempotent problem)

Create datasource:

  • name: Create prometheus private datasource
    loop_control:
    label: "PRIVATE ==> Environment: {{ item.name }} ==> Cluster: {{ item.cluster }} URL: {{ item.url }} , APPLICATION: URL: {{ url }}"
    community.grafana.grafana_datasource:
    state: present
    grafana_url: "{{ url }}"
    grafana_api_key: "{{ api_key_private }}"
    name: "{{ item.name }}"
    ds_type: prometheus
    ds_url: {{ url }}.{{ item.cluster }}.{{ item.url }}
    access: proxy
    tls_skip_verify: true
    additional_json_data:
    httpHeaderName1: "Authorization"
    additional_secure_json_data:
    httpHeaderValue1: "Bearer {{ item.token }}"
    with_items:
    • "{{ grafana_vars.prometheus_datasource }}"

Create dashboards:

  • name: Import Grafana private dashboards
    community.grafana.grafana_dashboard:
    grafana_url: "{{ url }}"
    grafana_api_key: "{{ api_key_private }}"
    state: present
    folder: "{{ item.0.name }}"
    commit_message: Updated by ansible
    overwrite: true
    path: "/tmp/{{ item.1 }}"
    loop_control:
    label: "PRIVATE_GRAFANA_PART ==> URL: {{ url }} DASHBOARDS: {{ item.1 }} ==> INTO FOLDER: {{ item.0.name }}"
    loop: "{{ grafana_envportal.folders | subelements('dashboards') }}"

Output:

TASK [grafana_deploy : Create prometheus private datasource] ******************************************************************************************************************************************************
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE

!!!CHANGED!!! but datasources exist!
TASK [grafana_deploy : Create prometheus public datasource] *******************************************************************************************************************************************************
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC

TASK [grafana_deploy : Create private alertmanager datasource] ****************************************************************************************************************************************************
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE
ok: [localhost] => (item=PRIVATE

!!!CHANGED!!! but datasources exist!
TASK [grafana_deploy : Create public alertmanager datasource] *****************************************************************************************************************************************************
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC
changed: [localhost] => (item=PUBLIC

!!!CHANGED!!!
TASK [grafana_deploy : Import Grafana private dashboards] *********************************************************************************************************************************************************
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART
changed: [localhost] => (item=PRIVATE_GRAFANA_PART

TASK [grafana_deploy : Import Grafana public dashboards] **********************************************************************************************************************************************************
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART
changed: [localhost] => (item=PUBLIC_GRAFANA_PART

Thanks for your answer. :)

@adamsipo adamsipo changed the title Problem with idempotent playbook , overide and datasources Problem with idempotent playbook , overwrite and datasources Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant