Skip to content

Add new config module to set keyboard layout#1176

Merged
TheRealFalcon merged 4 commits into
canonical:mainfrom
maxnet:keyboard
Jan 12, 2022
Merged

Add new config module to set keyboard layout#1176
TheRealFalcon merged 4 commits into
canonical:mainfrom
maxnet:keyboard

Conversation

@maxnet
Copy link
Copy Markdown
Contributor

@maxnet maxnet commented Jan 8, 2022

Proposed Commit Message

Add new config module to set keyboard layout

Adds a new module to allow setting keyboard layout,
for use-cases in which cloud-init is used to configure
OS images meant for physical computers instead
of the cloud.

This initial release only implements support
for Linux distributions that allow layout to be
set through systemd's localectl.

LP: #1951593

Test Steps

Allow setting keyboard layout like this:

#cloud-config
keyboard:
    layout: us

Or if you need more specific options:

#cloud-config
keyboard:
    layout: de
    model: pc105
    variant: nodeadkeys
    options: compose:rwin

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

maxnet added 2 commits January 9, 2022 00:22
Adds a new module to allow setting keyboard layout,
for use-cases in which cloud-init is used to configure
OS images meant for physical computers instead
of the cloud.

This initial release only implements support
for Linux distributions that allow layout to be
set through systemd's localectl.

Closes https://bugs.launchpad.net/cloud-init/+bug/1951593
@maxnet maxnet changed the title Keyboard Add new config module to set keyboard layout Jan 8, 2022
- Add keyboard module to modules.rst
- Add comments to examples
@TheRealFalcon TheRealFalcon self-assigned this Jan 11, 2022
Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon 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 the very thorough PR!

Code looks good. Can we add a few small docs changes?

diff --git a/cloudinit/config/cc_keyboard.py b/cloudinit/config/cc_keyboard.py
index e9165e06c..626ce812e 100644
--- a/cloudinit/config/cc_keyboard.py
+++ b/cloudinit/config/cc_keyboard.py
@@ -25,7 +25,7 @@ DEFAULT_KEYBOARD_MODEL = "pc105"
 meta = {
     "id": "cc_keyboard",
     "name": "Keyboard",
-    "title": "set keyboard layout",
+    "title": "Set keyboard layout",
     "description": dedent(
         """\
         Handle keyboard configuration.
@@ -65,7 +65,7 @@ schema = {
                     "type": "string",
                     "description": dedent(
                         """\
-                        Keyboard layout. Corresponds to XKBLAYOUT.
+                        Required. Keyboard layout. Corresponds to XKBLAYOUT.
                         """
                     ),
                 },
@@ -74,7 +74,7 @@ schema = {
                     "default": DEFAULT_KEYBOARD_MODEL,
                     "description": dedent(
                         """\
-                        Keyboard model. Corresponds to XKBMODEL.
+                        Optional. Keyboard model. Corresponds to XKBMODEL.
                         """
                     ),
                 },
@@ -82,7 +82,7 @@ schema = {
                     "type": "string",
                     "description": dedent(
                         """\
-                        Keyboard variant. Corresponds to XKBVARIANT.
+                        Optional. Keyboard variant. Corresponds to XKBVARIANT.
                         """
                     ),
                 },
@@ -90,7 +90,7 @@ schema = {
                     "type": "string",
                     "description": dedent(
                         """\
-                        Keyboard options. Corresponds to XKBOPTIONS.
+                        Optional. Keyboard options. Corresponds to XKBOPTIONS.
                         """
                     ),
                 },

Other than that, looks good to me!

@maxnet
Copy link
Copy Markdown
Contributor Author

maxnet commented Jan 12, 2022

Thanks for the review. Added the doc changes.

Copy link
Copy Markdown
Contributor

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Thanks!

@Sistem-Pack
Copy link
Copy Markdown

Hi everyone! I'am use autoinstall Ubuntu desktop. How I can add 2 keyboard layouts into installed OC?
I'm checked helps and documentations ... after 3 days late in my search can't found answer of my questuion.
I'm know what need use:
settings set org.gnome.desktop.input-sources sources "[('xkb', 'us'), ('xkb', 'fr')]"
and this command not work in late-command's and not work in use directive user-data into runcmd.
Where I'm find it?

P.S. Sorry, if I'm writing in the wrong place.

@aciba90
Copy link
Copy Markdown
Contributor

aciba90 commented Dec 15, 2023

Hi, @Sistem-Pack.

cloud-init.keyboard nor subiquity/autoinstall.keyboard modules have the ability to configure more than one keyboard.

Note that late-commands run in the installer environment, not in the target system. (If you want to understand more about the difference between the installation environment and how are subiquity/autoinstall and cloud-init related, see Interactions between autoinstall and cloud-init).

To run your commands in the target environment, do:

#cloud-config
autoinstall:
  version: 1
  ...
  user-data:
    runcmd:
      - [settings, set org.gnome.desktop.input-sources, sources, "\"[('xkb', 'us'), ('xkb', 'fr')]\""]

For more dynamic questions/support, you can contact IRC channels at Libera Chat: #ubuntu-server, #ubuntu-desktop and/or #cloud-init.

Or if you believe there is an issue / missing feature, create a ticket in https://bugs.launchpad.net/subiquity or https://github.com/canonical/cloud-init/issues.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants