ceph-grafana: Set grafana uid/gid on files

We don't need to create a grafana system user (in fact we even don't
set the righ uid to this user) because we're using a container setup.
Instead we just need to be sure to set the owner/group to 472 (grafana
user/group from the container) like we do for ceph/167.
We don't need to set the user/group recursively on /etc/grafana
directory in a dedicated task.
Also on Ubuntu system, the ceph-grafana-dashboards isn't present so on
non containerized deployment we won't have the
/etc/grafana/dashboards/ceph-dashboard directory present (coming with
the package) so we need to be sure it exists.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
(cherry picked from commit 34036c667c)
pull/4318/merge
Dimitri Savineau 2019-07-30 16:09:47 -04:00 committed by Guillaume Abrioux
parent 6a5308fa7f
commit 308e5fe9f4
2 changed files with 17 additions and 19 deletions

View File

@ -6,7 +6,7 @@
register: result register: result
until: result is succeeded until: result is succeeded
when: when:
- not containerized_deployment - not containerized_deployment | bool
- ansible_os_family in ['RedHat', 'Suse'] - ansible_os_family in ['RedHat', 'Suse']
tags: package-install tags: package-install
@ -25,7 +25,10 @@
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
recurse: yes recurse: yes
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
with_items: with_items:
- "/etc/grafana/dashboards/ceph-dashboard"
- "/etc/grafana/provisioning/datasources" - "/etc/grafana/provisioning/datasources"
- "/etc/grafana/provisioning/dashboards" - "/etc/grafana/provisioning/dashboards"
- "/etc/grafana/provisioning/notifiers" - "/etc/grafana/provisioning/notifiers"
@ -34,18 +37,24 @@
template: template:
src: grafana.ini.j2 src: grafana.ini.j2
dest: /etc/grafana/grafana.ini dest: /etc/grafana/grafana.ini
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640 mode: 0640
- name: write datasources provisioning config file - name: write datasources provisioning config file
template: template:
src: datasources-ceph-dashboard.yml.j2 src: datasources-ceph-dashboard.yml.j2
dest: /etc/grafana/provisioning/datasources/ceph-dashboard.yml dest: /etc/grafana/provisioning/datasources/ceph-dashboard.yml
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640 mode: 0640
- name: Write dashboards provisioning config file - name: Write dashboards provisioning config file
template: template:
src: dashboards-ceph-dashboard.yml.j2 src: dashboards-ceph-dashboard.yml.j2
dest: /etc/grafana/provisioning/dashboards/ceph-dashboard.yml dest: /etc/grafana/provisioning/dashboards/ceph-dashboard.yml
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640 mode: 0640
when: not containerized_deployment | bool when: not containerized_deployment | bool
@ -53,6 +62,8 @@
copy: copy:
src: "{{ grafana_crt }}" src: "{{ grafana_crt }}"
dest: "/etc/grafana/ceph-dashboard.crt" dest: "/etc/grafana/ceph-dashboard.crt"
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0640 mode: 0640
when: when:
- grafana_crt | bool - grafana_crt | bool
@ -62,6 +73,8 @@
copy: copy:
src: "{{ grafana_key }}" src: "{{ grafana_key }}"
dest: "/etc/grafana/ceph-dashboard.key" dest: "/etc/grafana/ceph-dashboard.key"
owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
mode: 0440 mode: 0440
when: when:
- grafana_key | bool - grafana_key | bool
@ -70,21 +83,12 @@
- name: generate a Self Signed OpenSSL certificate for dashboard - name: generate a Self Signed OpenSSL certificate for dashboard
shell: | shell: |
test -f /etc/grafana/ceph-dashboard.key -a -f /etc/grafana/ceph-dashboard.crt || \ test -f /etc/grafana/ceph-dashboard.key -a -f /etc/grafana/ceph-dashboard.crt || \
openssl req -new -nodes -x509 -subj '/O=IT/CN=ceph-grafana' -days 3650 -keyout /etc/grafana/ceph-dashboard.key -out /etc/grafana/ceph-dashboard.crt -extensions v3_ca (openssl req -new -nodes -x509 -subj '/O=IT/CN=ceph-grafana' -days 3650 -keyout /etc/grafana/ceph-dashboard.key -out /etc/grafana/ceph-dashboard.crt -extensions v3_ca && \
chown {{ grafana_uid }}:{{ grafana_uid }} /etc/grafana/ceph-dashboard.key /etc/grafana/ceph-dashboard.crt)
when: when:
- dashboard_protocol == "https" - dashboard_protocol == "https"
- not grafana_key | bool or not grafana_crt | bool - not grafana_key | bool or not grafana_crt | bool
- name: set owner/group on /etc/grafana
file:
path: /etc/grafana
state: directory
# This is the UID used by the grafana container
owner: "{{ grafana_uid }}"
# This group is used by the grafana rpm
group: "grafana"
recurse: true
- name: enable and start grafana - name: enable and start grafana
service: service:
name: grafana-server name: grafana-server

View File

@ -1,16 +1,10 @@
--- ---
- name: create grafana user
user:
name: grafana
shell: '/bin/false'
createhome: false
system: true
- name: create /etc/grafana and /var/lib/grafana - name: create /etc/grafana and /var/lib/grafana
file: file:
path: "{{ item }}" path: "{{ item }}"
state: directory state: directory
owner: "{{ grafana_uid }}" owner: "{{ grafana_uid }}"
group: "{{ grafana_uid }}"
recurse: true recurse: true
with_items: with_items:
- /etc/grafana - /etc/grafana