In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use Ansible to configure desktop settings in linux", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to use Ansible to configure desktop settings in linux" this article.
Set up wallpaper and lock screen
First, we will create a task manual to save our GNOME settings. In the root directory of the repository, there should be a file named local.yml, adding the following line:
-include: tasks/gnome.yml
The entire file should look like this:
-hosts: localhost become: true pre_tasks:-name: update repositories apt: update_cache=yes changed_when: False tasks:-include: tasks/users.yml-include: tasks/cron.yml-include: tasks/packages.yml-include: tasks/gnome.yml
Basically, this adds a reference to the file named gnome.yml, which will be stored in the tasks directory in the repository. We haven't created this file yet, let's create it now. Create a gnome.yml file in the tasks directory and put the following in:
-name: Install python-psutil package apt: name=python-psutil-name: Copy wallpaper file copy: src=files/wallpaper.jpg dest=/home/jay/.wallpaper.jpg owner=jay group=jay mode=600-name: Set GNOME Wallpaper become_user: jay dconf: key= "/ org/gnome/desktop/background/picture-uri" value= "'file:///home/jay/.wallpaper.jpg'"
Note that this code refers to my user name (jay) many times, so be sure to replace the jay that appears each time with the user name on your machine. In addition, if you do not use Ubuntu 18.04 as I did, you will have to change the apt line to match the package manager of your chosen distribution, and confirm the name of the python-psutil package, as it may be different.
In the sample task, I referenced the wallpaper.jpg file in the file directory, which must exist or the Ansible configuration will fail. In the tasks directory, create a subdirectory called files. Find your favorite wallpaper picture, name it wallpaper.jpg, and put it in the files directory. If the file is a PNG image instead of JPG, change the file extension in the code and repository. If you feel uncreative, I have a sample wallpaper file in the GitHub repository that you can use.
After all these changes are made, commit the content to the GitHub repository and push the changes. To sum up, you should complete the following tasks:
Modify the local.yml file to reference tasks/gnome.yml
Create a tasks/gnome.yml using the content mentioned above
Create a files directory in the tasks directory with an image file called wallpaper.jpg (or whatever name you choose).
After completing these steps and pushing the changes to the warehouse, the configuration should be applied automatically during the next scheduled run. You may remember that we automated this in the last article. ) if you want to save time, you can apply the configuration immediately using the following command:
Sudo ansible-pull-U https://github.com//ansible.git
If everything is all right, you should be able to see your new wallpaper.
Let's take a moment to understand the features of the new GNOME task manual. First, we added a plan to install the python-psutil package. If we don't add it, we won't be able to use the dconf module because it needs to install the package before changing the GNOME settings. Next, we use the copy module to copy the wallpaper file to our home directory and name the resulting file a hidden file that begins with a dot. If you don't want this file to be in the root of the home directory, you can always instruct this section to copy it to another location-as long as you reference it in the correct location, it still works. In the next plan, we use the dconf module to change the GNOME settings. In this case, we adjusted the / org/gnome/desktop/background/picture-uri key and set it to file:///home/jay/.wallpaper.jpg. Note the quotation marks in this section-you must use two single quotes in the dconf value, and if the value is a string, it must also be enclosed in double quotes.
Now, let's go further and apply the background to the lock screen. This is the current GNOME mission manual, but two additional plans have been added:
-name: Install python-psutil package apt: name=python-psutil-name: Copy wallpaper file copy: src=files/wallpaper.jpg dest=/home/jay/.wallpaper.jpg owner=jay group=jay mode=600-name: Set GNOME wallpaper dconf: key= "/ org/gnome/desktop/background/picture-uri" value= "'file:///home/jay/.wallpaper.jpg'"-name: Copy lockscreenfile copy: src=files/lockscreen.jpg dest=/home/jay/.lockscreen.jpg owner=jay group=jay mode=600-name: Set lockscreen background become_user: jay dconf: Key= "/ org/gnome/desktop/screensaver/picture-uri" value= "'file:///home/jay/.lockscreen.jpg'"
As you can see, what we do is much the same as when we set the wallpaper. We added two additional tasks, one is to copy the lock screen image and put it in our home directory, and the other is to apply the settings to GNOME so that we can use it. Also, be sure to change jay to your user name, name the lock screen image lockscreen.jpg you want, and copy it to the files directory. After these changes are committed to the warehouse, the new lock screen will be applied during the next planned Ansible run.
Apply a new desktop theme
Setting wallpaper and lock screen backgrounds is cool, but let's take desktop themes a step further. First, let's add an instruction to our task manual to install the arc-themed package. Add the following code to the beginning of the GNOME task manual:
-name: Install arc theme apt: name=arc-theme
Then, at the bottom, add the following action:
-name: Set GTK theme become_user: jay dconf: key= "/ org/gnome/desktop/interface/gtk-theme" value= "'Arc'"
Have you seen GNOME's GTK theme change before your eyes? We added an action to install the arc-theme package through the apt module, and another action to apply this theme to GNOME.
Make other customizations
Now that you have changed some GNOME settings, you can add other customizations as you like. Any settings you adjust in GNOME can be done automatically in this way, and setting wallpapers and themes are just a few examples. You may want to know how to find the settings you want to change. Here is a technique I use.
First, take a snapshot of all current dconf settings by running the following command on the computer you manage:
Dconf dump / > before.txt
This command exports all current changes to a file named before.txt. Next, manually change the settings you want to automate and get the dconf settings again:
Dconf dump / > after.txt
Now, you can use the diff command to see the differences between the two files:
Diff before.txt after.txt
This should give you a list of changed key values. While manually changing settings does run counter to the purpose of automation, what you're actually doing is getting the keys you changed when you updated the settings, which allows you to create an Ansible task to modify these settings so that you don't have to touch them anymore. If you need to restore the machine, the Ansible repository will take care of each of your customizations. If you have multiple computers, or even a group of workstations, you only need to make a manual change, and all other workstations will apply the new settings and fully synchronize.
These are all the contents of the article "how to configure Desktop Settings with Ansible in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.