Change dconf keys without logging into X in Puppet
Joril, thanks for providing your solution! I would like to add one comment in case people have the problem that I just did: when you use this type definition to set string values, you need to pass in some extra quotes and escape characters. For instance, I wanted to set my color scheme in gedit, so I tried this:
dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
value => 'solarized_dark',
}
but it didn't work. What I needed to do was this:
dconf::key {'/org/gnome/gedit/preferences/editor/scheme':
value => "\\\"solarized_dark\\\"",
}
Maybe someone could do that in a simpler way, or build it into the function you provided? Anyway, it works for me now so I'm leaving it alone.
Note that passing in booleans works fine without that extra nonsense, e.g.:
dconf::key {'/org/gnome/gedit/preferences/editor/auto-indent':
value => 'true',
}
works correctly, and I'm assuming that numerical values can probably be set without extra escape characters as well.
I managed to solve the problem:
define dconf::key($value) {
exec { "Setting dconf $title":
path => "/bin:/usr/bin",
command => "/bin/sh -c 'eval `dbus-launch --auto-syntax` && dconf write $title $value'",
user => "user_name",
group => "user_name",
unless => "dconf read $title | grep $value",
require => Package["dconf-tools"]
}
}
I have created a puppet module for that, based on Joril's answer:
https://github.com/sitaktif/puppet-dconf
As user153385 mentions, it needs escaping because of the use of sh
. Examples with bool, string and array are given in the README.md
of the repository.