Closed Boy-Sittisak closed 1 year ago
@Boy-Sittisak what resources are you running before you use this resource? I believe you need a few other resources before using it which might be part of the problem. If you can provide a full example, that would be great.
@ramereth Thank for reply Here is cookbook recipe that I try to deploy with chef-client This cookbook able to run without problem until I add grafana_config_ldap_servers resource maybe I missed something and need to add before grafana_config_ldap_servers resource? I'm new to chef and grafana as well.
grafana_install 'grafana'
service 'grafana-server' do
action [:enable, :start]
subscribes :restart, ['template[/etc/grafana/grafana.ini]', 'template[/etc/grafana/ldap.toml]'], :delayed
end
grafana_config 'grafana' do
restart_on_upgrade true
end
grafana_config_server 'grafana' do
http_addr 'localhost'
http_port 3000
protocol :http
enable_gzip true
end
grafana_config_database 'grafana' do
type :mysql
host 'localhost:3306'
user 'grafana'
password '090CE11ce'
max_idle_conn 10
max_open_conn 30
ssl_mode false
action :install
end
grafana_config_auth 'grafana' do
ldap_enabled true
ldap_config_file '/etc/grafana/ldap.toml'
ldap_allow_sign_up true
end
grafana_config_ldap_servers 'grafana' do
host '127.0.0.1'
port 389
use_ssl false
start_tls false
ssl_skip_verify false
bind_dn 'cn=admin,dc=grafana,dc=org'
bind_password 'SuperSecretPassword'
search_filter '(cn=%s)'
search_base_dns %w( dc=grafana,dc=org )
end
grafana_config_ldap 'grafana' do
servers_attributes_name 'givenName'
servers_attributes_surname 'sn'
servers_attributes_username 'cn'
servers_attributes_member_of 'memberOf'
servers_attributes_email 'mail'
end
grafana_config_ldap_group_mappings 'grafana' do
group_dn 'cn=admins,dc=grafana,dc=org'
org_role 'Admin'
grafana_admin true
org_id 1
end
grafana_config_writer 'grafana'
@Boy-Sittisak I confirmed if you move grafana_config_ldap
before grafana_config_ldap_servers
, the issue goes away. It now complains about not having access to mysql but I assume you already have that setup in your environment. Can you please confirm this is works now for you?
@ramereth Thank you very much it work. I was confuse by original ldap.toml file as I see [[servers]] section come first so I through maybe I should put grafana_config_ldap_servers first.
If the documentation is not clear on this for our cookbook could you drop in a pr to make it easier to comprehend?
Thanks!
I'll open myself up here and say that unless there's a reason that I can't see right now, there's no reason that the grafana_config_ldap_servers
can't lazy create the parent ldap hash either I don't think which would make these work either way around.
I'll open myself up here and say that unless there's a reason that I can't see right now, there's no reason that the
grafana_config_ldap_servers
can't lazy create the parent ldap hash either I don't think which would make these work either way around.
Go for it and issue a PR? ;)
I did have a quick look yesterday but it turned into a big job as almost all of the config resources want changes making to them as it's obviously been done by someone that didn't appreciate the difference between a Chef::Mash and a normal ruby Hash.
I think the way to go is a helper to set the values to make sure the parent Hashes exist so that the resources can be used in any order. The nil
and concat things is just weird to me as well.
I'll probably have a pop at it soon as it'll eat away at me 😬
Only a quick attempt but thinking of something like this for setting values:
def run_state_config_set(hash, key, value, *path)
raise ArgumentError unless hash.is_a?(Hash)
hash['sous-chefs'] ||= {}
config_hash = hash['sous-chefs']
path.each do |pn|
config_hash[pn] ||= {}
config_hash = config_hash[pn]
end
config_hash[key] = value
end
So you pass the top level node.run_state in along with the setting and its value then walk down the path lazy creating the sub-hashes if they don't exist then set the final key/value at the bottom. Also the resources can then use a loop to set the values using property_is_set?
to skip if they property isn't set instead of all the unless and concat stuff.
Thoughts?
:speaking_head: Foreword
:ghost: Brief Description
Hello I'm trying to deploy Gafana with LDAP config with grafana_config_ldap_servers Resources even with all default setting it will get error message with "undefined method `[]' for nil:NilClass" when run chef-client
:pancakes: Cookbook version
9.6.2
:woman_cook: Chef-Infra Version
16.13.16
:tophat: Platform details
CentOS Linux release 7.9.2009
Steps To Reproduce
Steps to reproduce the behavior:
See this error message when run chef-client
:police_car: Expected behavior
Write ldap servers config to /etc/grafana/ldap.toml file
:heavy_plus_sign: Additional context
I'm not sure if I do something wrong or not but I tested with minimal required setting like below still the got same result