provisioning-local icon indicating copy to clipboard operation
provisioning-local copied to clipboard

Having some trouble with the dconf and gsetting plugins

Open elmehalawi opened this issue 9 years ago • 10 comments

I'm trying to set a dconf setting from an Ansible script (I cloned your repo). Here's my attempt:

- name: set resolution scaling
  dconf:
    key: /com/ubuntu/user-interface/scale-factor
    string: {'DP1': 12}

For some reason this isn't working. I also tried the equivalent using gsettings, and that also did not set the resolution scaling, and I don't get an error in either case. The strange thing is, if I set the scale factor to what it is right now, Ansible shows that nothing happened, but when I set it to something different, it shows that it was updated. That makes it sound like it's working perfectly, but for some reason, it's not actually changing.

It does change when I use either dconf write or gsettings set.

Anyway, I've been thinking about setting something like this up and this repo made it extremely easy. Thanks!

elmehalawi avatar Jul 21 '16 09:07 elmehalawi

Sorry, didn't notice this. This makes sense, it might be a bracketing issue with the {, it isn't detecting a change because whatever value it's setting, it is setting successfully. What happens if you read the value after running the script, what is it?

JBKahn avatar Jul 28 '16 03:07 JBKahn

It remains unchanged, as it was before I run ansible. When I looked at dconf-editor, I noticed the type of scale-factor was a{si}, not just string, so I tried this:

gconftool2:
    key: /com/ubuntu/user-interface/scale-factor
    pair-car-type: 'string'
    pair-cdr-type: 'int'
    pair: ['DP1','12']

But this also did not change the value. Not sure if a{si} is considered a "pair" by gconftool2.

elmehalawi avatar Jul 28 '16 03:07 elmehalawi

It's weird because even though it's not a string, it actually does update using the regular dconf write and gsettings set commands...

elmehalawi avatar Jul 28 '16 03:07 elmehalawi

turn on verbose mode to see the command it's running?

JBKahn avatar Jul 28 '16 03:07 JBKahn

I'm not really sure how to get the exact command. When I use -vvvv, it prints the command for running the plugin, but not the command the plugin itself runs. I was able to get this though:

ok: [127.0.0.1] => {
    "resolution": {
        "changed": true, 
        "key": "/com/ubuntu/user-interface/scale-factor", 
        "old_value": "{'DP1': 12}", 
        "value": "{'DP1': 10}"
    }
}

elmehalawi avatar Jul 28 '16 04:07 elmehalawi

If you run this command, as is, locally then does it work? https://github.com/JBKahn/provisioning-local/blob/master/ansible_modules/gconftool2#L93

JBKahn avatar Jul 28 '16 04:07 JBKahn

Actually, no. But dconf does work, and so does gsettings.

elmehalawi avatar Jul 28 '16 05:07 elmehalawi

did you try it with the gsettings command in the module, as I formatted it?

JBKahn avatar Jul 28 '16 16:07 JBKahn

Yes, here's the setting with the gsettings:

- name: set resolution scaling
  gsettings:
    schema: com.ubuntu.user-interface
    key: scale-factor
    string: "{'DP1', 10}"

I also tried using \{'DP1', 10\}, but that also didn't work.

Here's the line in the module which reads the string into the value variable:

value = '\'{}\''.format(string_value)

And here's the function which returns the command:

def _set_value(module, schema, key, value):
    """Set value of setting, under `key` in `schema`, using gsettings to `value`."""
    return module.run_command(" ".join(['gsettings set {} {} {}'.format(schema, key, value)]))

It all seems to add up. When I try that same line in the terminal it works. Not sure what I'm missing here.

elmehalawi avatar Jul 28 '16 21:07 elmehalawi

Are you sure the user it's using to set the value is the correct one? You can try specifying that? You can also use a break point and test that line, I think i wrote a blog post about testing modules a while back.

On Thu, Jul 28, 2016, 5:54 PM dublinus [email protected] wrote:

Yes, here's the setting with the gsettings:

  • name: set resolution scaling gsettings: schema: com.ubuntu.user-interface key: scale-factor string: "{'DP1', 10}"

I also tried using {'DP1', 10}, but that also didn't work.

Here's the line in the module which reads the string into the value variable:

value = ''{}''.format(string_value)

And here's the function which returns the command:

def _set_value(module, schema, key, value): """Set value of setting, under key in schema, using gsettings to value.""" return module.run_command(" ".join(['gsettings set {} {} {}'.format(schema, key, value)]))

It all seems to add up. When I try that same line in the terminal it works. Not sure what I'm missing here.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/JBKahn/provisioning-local/issues/19#issuecomment-236037036, or mute the thread https://github.com/notifications/unsubscribe-auth/ACiBvchJV20dy7IIA6OEZFf6a4tUI3Mtks5qaSUjgaJpZM4JRmhd .

JBKahn avatar Jul 28 '16 22:07 JBKahn