Skip to content

dconf_module: add feature: populate a subpath from file #10432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

Sh3idan
Copy link

@Sh3idan Sh3idan commented Jul 19, 2025

SUMMARY

This merge request allows to populate a subpath from file by using load sub-command of the dconf binary. Below the changes that were made:

  • state: load has been added to address the feature
  • path is a new option working with the feature. It points to a file located in node which contains a subpath dump.
  • key remains unchanged but, here, it refers to a root directory (instead of a dconf key) and must be '/' terminated
ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

dconf

ADDITIONAL INFORMATION

Below a role using the newly load state, followed by the varbatim output:

- name: Apply profile for Gnome terminal
  ansible.builtin.dconf:
    key: "/org/gnome/terminal/legacy/profiles:/"
    path: "/tmp/solarized_dark.dump"
    state: load
changed: [192.168.1.1] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "key": "/org/gnome/terminal/legacy/profiles:/",
            "path": "/tmp/solarized_dark.dump",
            "state": "load",
            "value": null
        }
    }
}

The content of the path file is:

[:b1daa9dd-6252-4d8d-a863-c897e6d619b9]
background-color='rgb(0,43,54)'
bold-is-bright=false
foreground-color='rgb(131,148,150)'
palette=['rgb(7,54,66)', 'rgb(220,50,47)', 'rgb(133,153,0)', 'rgb(181,137,0)', 'rgb(38,139,210)', 'rgb(211,54,130)', 'rgb(42,161,152)', 'rgb(238,232,213)', 'rgb(0,43,54)', 'rgb(203,75,22)', 'rgb(88,110,117)', 'rgb(101,123,131)', 'rgb(131,148,150)', 'rgb(108,113,196)', 'rgb(147,161,161)', 'rgb(253,246,227)']
use-theme-colors=false

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added feature This issue/PR relates to a feature request module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) labels Jul 19, 2025
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the ci_verified Push fixes to PR branch to re-run CI label Jul 19, 2025
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 19, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-11 Automatically create a backport for the stable-10 branch labels Jul 19, 2025
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

Sh3idan and others added 2 commits July 19, 2025 13:28
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 19, 2025
@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 19, 2025
# NOTE: This case shouldn't happen yet as 'key' and 'path' are
# required with 'state=present'
# TODO: if 'key' ends with '/' then 'dconf list' should be used
# else, 'dconf read'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this TODO be part of dconf.load()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't thing so.

The architecture defined by the original author suggests that:

  • dconf.read handles dconf read [key]
  • dconf.write handles dconf write [key] [value]
  • dconf.load handles dconf load [key] < [path] (this contribution)

If key ends with '/', it means that it's a directory. If value is set, it should be illegal. If path is set, we're in the case of the contribution. If none of them is set, user tries to read a directory. It cannot be handled neither by dconf read nor dconf dump instead, dconf list must be used. In the future, dconf.list must be created to by compliant.

As you said, state=read is a mistake. As I understand, it means that reading key (whatever the meaning - a key or a directory) should have been handled by state=present. That's why I added this TODO here.

Are you agree with that?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you said, state=read is a mistake. As I understand, it means that reading key (whatever the meaning - a key or a directory) should have been handled by state=present. That's why I added this TODO here.

What do you mean that read is a mistake? The read state is meant to read the key value without making changes to it - the present state will/might change the value. Or have I misunderstood something here?


# Run the command and fetch standard return code, stdout, and stderr.
dbus_wrapper = DBusWrapper(self.module)
rc, out, err = dbus_wrapper.run_command(command, data=raw_config)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to keys that already exist, but are not part of raw_config? Are these kept, or removed?

If the latter, the changed check above is not correct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If keys exist in the database but, are not part of raw_config then they're kept. changed check should be correct!

Sh3idan and others added 2 commits July 20, 2025 13:10
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 20, 2025
Sh3idan and others added 2 commits July 20, 2025 21:49
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
@ansibullbot ansibullbot removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jul 20, 2025
Sh3idan and others added 5 commits July 20, 2025 22:21
This update allows:
* Compatibility between python2 and python3
* To handle IO operation errors

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
@Sh3idan
Copy link
Author

Sh3idan commented Jul 20, 2025

Note that I added a sub-function (_create_dconf_key) to fix a bug when raw_config contains entry at the root.

Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Sh3idan, thanks for your contribution.

I have some other comments as well.

@@ -61,10 +61,17 @@
description:
- Value to set for the specified dconf key. Value should be specified in GVariant format. Due to complexity of this
format, it is best to have a look at existing values in the dconf database.
- Required for O(state=present).
- Required for O(state=present). If provided, O(path) is not required.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I may suggest:

Suggested change
- Required for O(state=present). If provided, O(path) is not required.
- O(path) and O(value) are mutually exclusive, but one of them is required when O(state=present).

Same text in path below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your comment is outdated. Please, tell me if the Felix's suggestions are correct. If not, I'll updated them.

Comment on lines 444 to 448
changed = any(
not self.variants_are_equal(self.read("%s%s/%s" % (root_dir, sub_dir, k)), v)
for sub_dir in config.sections()
for k, v in config[sub_dir].items()
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I presume you are doing this because dconf will not report whether any value was changed, is that so?

Copy link
Author

@Sh3idan Sh3idan Jul 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why i'm doing this. Should I also check if the keys have actually been added?

Sh3idan and others added 3 commits July 22, 2025 21:47
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-11 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants