diff --git a/roles/grafana/defaults/main.yml b/roles/grafana/defaults/main/config.yml similarity index 85% rename from roles/grafana/defaults/main.yml rename to roles/grafana/defaults/main/config.yml index 424f2bd..7ed160c 100644 --- a/roles/grafana/defaults/main.yml +++ b/roles/grafana/defaults/main/config.yml @@ -1,50 +1,4 @@ --- -grafana_user: grafana -grafana_version: "11.3.0" -grafana_base_path: "/opt/grafana" -grafana_config_path: "{{ grafana_base_path }}/config" -grafana_config_file: "{{ grafana_config_path }}/grafana.ini" -grafana_ldap_config_file: "{{ grafana_config_path }}/ldap.toml" -grafana_provisioning_path: "{{ grafana_config_path }}/provisioning" -grafana_notifier_provisioning_path: "{{ grafana_provisioning_path }}/notifiers" -grafana_dashboard_provisioning_path: "{{ grafana_provisioning_path }}/dashboards" -grafana_datasource_provisioning_path: "{{ grafana_provisioning_path }}/datasources" -grafana_plugin_provisioning_path: "{{ grafana_provisioning_path }}/plugins" -grafana_data_path: "{{ grafana_base_path }}/data" -grafana_logs_path: "{{ grafana_base_path }}/logs" -grafana_state: present - -grafana_run_user: >- - {{ ('uid' in (grafana_user_info | default([]))) | ternary(grafana_user_info.uid, grafana_user) }} -grafana_run_group: >- - {{ ('group' in (grafana_user_info | default([]))) | ternary(grafana_user_info.group, grafana_user) }} - -grafana_container_image_server: "docker.io" -grafana_container_image_namespace: "grafana" -grafana_container_image_container: "grafana" -grafana_container_image_name: >- - {{ - [ - ((grafana_container_image_server is defined) - | ternary([ grafana_container_image_server ], [])), - ((grafana_container_image_namespace is defined) - | ternary([ grafana_container_image_namespace], [])), - grafana_container_image_container, - ] | ansible.builtin.flatten | join('/') - }} -grafana_container_image: >- - {{ grafana_container_image_name }}:{{ grafana_container_image_tag | default(grafana_version, true) }} - -grafana_container_name: grafana -grafana_container_base_volumes: - - "{{ grafana_config_path }}:{{ grafana_container_config_path }}:ro" - - "{{ grafana_data_path }}:{{ grafana_container_data_path }}:rw" - - "{{ grafana_logs_path }}:{{ grafana_container_logs_path }}:rw" -grafana_container_volumes: [] -grafana_container_collected_volumes: >- - {{ grafana_container_base_volumes + grafana_container_volumes }} -grafana_container_restart_policy: "unless-stopped" - grafana_config_log_mode: - console - file diff --git a/roles/grafana/defaults/main/container.yml b/roles/grafana/defaults/main/container.yml new file mode 100644 index 0000000..aa27cd0 --- /dev/null +++ b/roles/grafana/defaults/main/container.yml @@ -0,0 +1,26 @@ +--- +grafana_container_image_server: "docker.io" +grafana_container_image_namespace: "grafana" +grafana_container_image_container: "grafana" +grafana_container_image_name: >-2 + {{ + [ + ((grafana_container_image_server is defined) + | ternary([ grafana_container_image_server ], [])), + ((grafana_container_image_namespace is defined) + | ternary([ grafana_container_image_namespace], [])), + grafana_container_image_container, + ] | ansible.builtin.flatten | join('/') + }} +grafana_container_image: >-2 + {{ grafana_container_image_name }}:{{ grafana_container_image_tag | default(grafana_version, true) }} + +grafana_container_name: grafana +grafana_container_base_volumes: + - "{{ grafana_config_path }}:{{ grafana_container_config_path }}:ro" + - "{{ grafana_data_path }}:{{ grafana_container_data_path }}:rw" + - "{{ grafana_logs_path }}:{{ grafana_container_logs_path }}:rw" +grafana_container_volumes: [] +grafana_container_collected_volumes: >-2 + {{ grafana_container_base_volumes + grafana_container_volumes }} +grafana_container_restart_policy: "unless-stopped" diff --git a/roles/grafana/defaults/main/main.yml b/roles/grafana/defaults/main/main.yml new file mode 100644 index 0000000..53836e9 --- /dev/null +++ b/roles/grafana/defaults/main/main.yml @@ -0,0 +1,20 @@ +--- +grafana_user: grafana +grafana_version: "11.3.0" +grafana_base_path: "/opt/grafana" +grafana_config_path: "{{ grafana_base_path }}/config" +grafana_config_file: "{{ grafana_config_path }}/grafana.ini" +grafana_ldap_config_file: "{{ grafana_config_path }}/ldap.toml" +grafana_provisioning_path: "{{ grafana_config_path }}/provisioning" +grafana_notifier_provisioning_path: "{{ grafana_provisioning_path }}/notifiers" +grafana_dashboard_provisioning_path: "{{ grafana_provisioning_path }}/dashboards" +grafana_datasource_provisioning_path: "{{ grafana_provisioning_path }}/datasources" +grafana_plugin_provisioning_path: "{{ grafana_provisioning_path }}/plugins" +grafana_data_path: "{{ grafana_base_path }}/data" +grafana_logs_path: "{{ grafana_base_path }}/logs" +grafana_state: present + +grafana_run_user: >- + {{ ('uid' in (grafana_user_info | default([]))) | ternary(grafana_user_info.uid, grafana_user) }} +grafana_run_group: >- + {{ ('group' in (grafana_user_info | default([]))) | ternary(grafana_user_info.group, grafana_user) }} diff --git a/roles/grafana/tasks/main.yml b/roles/grafana/tasks/main.yml index 7153987..9a7063d 100644 --- a/roles/grafana/tasks/main.yml +++ b/roles/grafana/tasks/main.yml @@ -2,7 +2,7 @@ - name: Ensure grafana_state is valid ansible.builtin.assert: that: - - "grafana_state in ['present', 'absent']" + - "grafana_state in grafana_states" fail_msg: >- Only 'present' and 'absent' are allowed as values for grafana_state diff --git a/roles/grafana/vars/main.yml b/roles/grafana/vars/main.yml index 1ca745a..bee3a09 100644 --- a/roles/grafana/vars/main.yml +++ b/roles/grafana/vars/main.yml @@ -1,4 +1,7 @@ --- +grafana_states: + - present + - absent grafana_container_config_path: "/etc/grafana" grafana_container_data_path: "/var/lib/grafana" grafana_container_logs_path: "/var/log/grafana"