mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-03-21 02:10:11 +08:00
Merge branch 'master' of https://github.com/LCTT/TranslateProject into translating
This commit is contained in:
commit
92e5e194d3
76
published/20191125 My top 5 Ansible modules.md
Normal file
76
published/20191125 My top 5 Ansible modules.md
Normal file
@ -0,0 +1,76 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12304-1.html)
|
||||
[#]: subject: (My top 5 Ansible modules)
|
||||
[#]: via: (https://opensource.com/article/19/11/ansible-modules)
|
||||
[#]: author: (Mark Phillips https://opensource.com/users/markp)
|
||||
|
||||
我最喜欢用的 5 个 Ansible 模块
|
||||
======
|
||||
|
||||
> 了解如何通过这些 Ansible 模块实现几乎任何事情。
|
||||
|
||||

|
||||
|
||||
在我成长的时候,我爷爷在他的花园里有一个棚子。他经常会花几个小时在那里制作和修复东西。这是在我们有互联网之前的事情,所以我花了很多时间看他在那个棚子里创造东西。虽然棚子里有很多工具,从钻头到车床到电器配件,还有很多东西我至今都无法辨认,但他使用的只是他手头的一小部分。然而,他能做到的事情似乎永远没有极限。
|
||||
|
||||
我之所以告诉你这个故事,是因为我觉得我的职业生涯是在一个隐喻的棚子里度过的。计算机也是如此多的工具,都在一个狭小(虚拟?)的空间里。而工具棚中又有工具棚 —— 我最喜欢的是 Ansible。最近的 2.9 版本有 3,681 个模块! **3,681 个啊!**当我在 2013 年夏天第一次开始使用 Ansible 时,1.2.1 版本只有 113 个模块,然而,正如[我当时写的][2],我仍然可以实现任何我想象到的东西。
|
||||
|
||||
模块是 Ansible 的支柱,是让重任轻装上阵的齿轮。它们被设计为做好一项工作,从而实现了 [Unix 哲学][3]。我们就是这样来把这么多的模块捆绑在一起,作为乐团的指挥,Ansible 现在有很多乐器可以听从它的指挥。
|
||||
|
||||
回顾一下我多年来的 Ansible 剧本和角色的 Git 仓库,我发现我只用了 35 个模块。这个小的子集被用来构建大型基础设施。不过,我想知道如果用一个更小的子集可以实现什么?当我回顾这 35 个模块时,我在思考,我能否只用 5 个模块就能达到同样的效果。因此,以下是我最喜欢的五个模块,顺序无关。
|
||||
|
||||
### 5. authorized_key
|
||||
|
||||
SSH 是 Ansible 的核心,至少对于除了 Windows 以外的几乎所有其他功能都是如此。在 Ansible 中高效使用 SSH 的关键(没有双关语)是……[密钥][5]!顺便提一下,你可以用 SSH 密钥为安全性做很多非常酷的事情。值得仔细阅读 [sshd 手册页][6]中的 “authorized_keys” 部分。如果你需要精细的用户访问控制,管理 SSH 密钥可能会变得很费力,尽管我可以用接下来的两个我最爱的模块中的任何一个,但我更喜欢使用 [authorized_key][4] 这个模块,因为它[可以通过变量轻松管理][7]。
|
||||
|
||||
### 4. file
|
||||
|
||||
除了显而易见的将文件放置在某个地方的功能外,[file][8] 模块还可以设置所有权和权限。我想说的是,这样一个模块就能带来很多的好处。很大一部分安全问题也与设置权限有关,所以 [file][8] 模块和 [authorized_key][4] 可以很好地配合在一起使用。
|
||||
|
||||
### 3. template
|
||||
|
||||
操作文件内容的方法太多了,我看到很多人都在使用 [lineinfile][10]。我自己也用它做过小任务。但是,[template][9] 模块就清晰多了,因为你维护了整个文件的上下文。我更喜欢以任何人都可以*轻松*理解的方式编写 Ansible 的内容 —— 对我而言,这意味着容易理解正在发生的事情。[template][9] 的使用意味着能够看到你正在放置内容的整个文件、全部你正在改变的变量。
|
||||
|
||||
### 2. uri
|
||||
|
||||
当前发布版中的许多模块利用 Ansible 作为编排工具。它们与另一个服务对话,而不是做一些具体的事情,比如把一个文件放到一个地方。通常,这种对话也是通过 HTTP 进行的。在许多这样的模块出现之前,你*可以*直接使用 [uri][11] 模块对 API 进行编程。它是一个强大的访问工具,可以使你能够做很多事情。在我的 Ansible 虚拟棚子里,我不会少了它。
|
||||
|
||||
### 1. shell
|
||||
|
||||
这是我们工具包里的王牌、瑞士军刀。如果你为如何控制其他东西而非常苦恼,别说,说就是 [shell][12]。有人会说,我们这样说是让 Ansible 成为了 Bash 脚本 —— 但是,我想说的是,这还是有点好处的,因为可以在你的剧本和角色中使用 `name` 参数记录下每一步。对我来说,这就像一个很大的奖励一样。早在我还在做咨询的时候,我曾经帮助一个数据库管理员(DBA)迁移到 Ansible。这位 DBA 并不喜欢改变,对改变工作方法也是推三阻四。于是,为了简化迁移到 Ansible 方式,我们在 Ansible 中使用 [shell][12] 模块调用了一些现有的数据库管理脚本。并在任务中附带了翔实的 `name` 声明。
|
||||
|
||||
通过这五个模块,你可以实现很多事情。是的,为完成特定任务而设计的模块会让你的生活更加轻松。但是,借助简单的工程设计,你几乎可以事半功倍。Ansible 开发者 Brian Coca 是这方面的大师,[他的技巧和窍门讲座][13]总是值得一看。
|
||||
|
||||
* * *
|
||||
|
||||
你觉得我喜欢的五大模块怎么样?如果你也必须限制在这么多模块,你会选择哪五个,为什么?在下面的评论中告诉我吧!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/ansible-modules
|
||||
|
||||
作者:[Mark Phillips][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[wxy](https://github.com/wxy)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/markp
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/mandelbrot_set.png?itok=bmPc0np5
|
||||
[2]: http://probably.co.uk/post/puppet-vs-chef-vs-ansible/
|
||||
[3]: https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well
|
||||
[4]: https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html
|
||||
[5]: https://linux.die.net/man/1/ssh-keygen
|
||||
[6]: https://linux.die.net/man/8/sshd
|
||||
[7]: https://github.com/phips/ansible-demos/blob/3bf59df1eb2390b31b5c42333197e2fbb7fec93f/roles/ansible-users/tasks/main.yml#L35
|
||||
[8]: https://docs.ansible.com/ansible/latest/modules/file_module.html
|
||||
[9]: https://docs.ansible.com/ansible/latest/modules/template_module.html
|
||||
[10]: https://docs.ansible.com/ansible/latest/modules/lineinfile_module.html
|
||||
[11]: https://docs.ansible.com/ansible/latest/modules/uri_module.html
|
||||
[12]: https://docs.ansible.com/ansible/latest/modules/shell_module.html
|
||||
[13]: https://www.ansible.com/ansible-tips-and-tricks
|
@ -1,8 +1,8 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (wxy)
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12302-1.html)
|
||||
[#]: subject: (Track Your Screen Time in Linux with ActivityWatch)
|
||||
[#]: via: (https://itsfoss.com/activitywatch/)
|
||||
[#]: author: (Ankush Das https://itsfoss.com/author/ankush/)
|
||||
@ -10,13 +10,15 @@
|
||||
使用 ActivityWatch 跟踪你在 Linux 中的屏幕使用时间
|
||||
======
|
||||
|
||||

|
||||
|
||||
> ActivityWatch 是一款开源的隐私友好型应用程序,可追踪你在台式电脑或移动设备上的使用时间。
|
||||
|
||||
### ActivityWatch: 一个追踪你在哪个应用程序上花了多少时间的开源应用程序
|
||||
|
||||
![ActivityWatch lets you check the time spent on various applications][1]
|
||||
|
||||
[ActivityWatch][2] 是一款跨平台的开源应用,可以帮助你追踪时间,衡量你的工作效率。它可以追踪你花在应用程序、浏览器上的时间,以及你是否 AFK(远离键盘)或系统处于休眠状态。
|
||||
[ActivityWatch][2] 是一款跨平台的开源应用,可以帮助你追踪使用时间,衡量你的工作效率。它可以追踪你花在应用程序、浏览器上的时间,以及你是否 AFK(远离键盘)或系统处于休眠状态。
|
||||
|
||||
不只是追踪时间,它还提供了一堆有用的功能,通过可视化的方式帮助你轻松分析你是如何花费时间的,从而有可能提高你的生产力。
|
||||
|
||||
@ -28,7 +30,7 @@ ActivityWatch 可用于 Linux、Windows、macOS 和 [Android][6]。它还提供
|
||||
|
||||
![][7]
|
||||
|
||||
它刚刚进入该领域,正在积极开发,以解决任何现有的问题,并引入新的功能,如在多个设备上同步你的活动数据的能力。
|
||||
它刚刚进入该领域,正在积极开发,以解决任何现有的问题并引入新的功能,如在多个设备上同步你的活动数据的能力。
|
||||
|
||||
**对于注重隐私的用户来说,我应该提到,收集的数据被存储在你本地的设备上。这是一件好事,因为你可以跟踪你的花费时间,而不会被别人跟踪。**
|
||||
|
||||
@ -36,7 +38,7 @@ ActivityWatch 可用于 Linux、Windows、macOS 和 [Android][6]。它还提供
|
||||
|
||||
![][8]
|
||||
|
||||
基本上,ActivityWatch 可以让你监控你的活动,以分析不良的屏幕使用时间,或改善你在设备上做事的时间管理。
|
||||
基本上,ActivityWatch 可以让你监控你的活动,以分析不良的屏幕使用时间,或改善你在设备上工作的时间管理。
|
||||
|
||||
具体来说,它提供了几个有用的功能,主要有:
|
||||
|
@ -1,8 +1,8 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: (geekpi)
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: reviewer: (wxy)
|
||||
[#]: publisher: (wxy)
|
||||
[#]: url: (https://linux.cn/article-12301-1.html)
|
||||
[#]: subject: (How to Install Nvidia Drivers on Fedora Linux)
|
||||
[#]: via: (https://itsfoss.com/install-nvidia-drivers-fedora/)
|
||||
[#]: author: (John Paul https://itsfoss.com/author/john/)
|
||||
@ -10,6 +10,8 @@
|
||||
如何在 Fedora Linux 中安装 Nvidia 驱动
|
||||
======
|
||||
|
||||

|
||||
|
||||
与大多数 Linux 发行版一样,[Fedora][1] 并未默认安装专有的 [Nvidia][2] 驱动。
|
||||
|
||||
默认的开源 [Nouveau 驱动][3]在大多数情况下都可以使用,但是你可能会遇到屏幕撕裂等问题。
|
||||
@ -38,15 +40,15 @@ sudo dnf update
|
||||
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
|
||||
```
|
||||
|
||||
不喜欢终端么?那使用 GUI 的方法添加 RPMFusion 仓库。
|
||||
|
||||
如果你使用 Firefox,那么还可以从浏览器添加 RPMFusion 仓库。进入[配置页面][7],然后向下滚动到 “Graphical Setup via Firefox web browser”。单击自由和非自由仓库链接。这将下载 .rpm 文件,并安装仓库。
|
||||
|
||||
![RPMFusion Browser Installation][8]
|
||||
|
||||
你可以双击下载的 RPM 文件进行安装。
|
||||
|
||||
![RPMFusion in the Software Center][9]
|
||||
> 不喜欢终端么?那使用 GUI 的方法添加 RPMFusion 仓库。
|
||||
>
|
||||
> 如果你使用 Firefox,那么还可以从浏览器添加 RPMFusion 仓库。进入这个[配置页面][7],然后向下滚动到 “Graphical Setup via Firefox web browser”。单击自由和非自由仓库的链接。这将下载 .rpm 文件,并安装仓库。
|
||||
>
|
||||
> ![RPMFusion Browser Installation][8]
|
||||
>
|
||||
> 你可以双击下载的 RPM 文件进行安装。
|
||||
>
|
||||
> ![RPMFusion in the Software Center][9]
|
||||
|
||||
#### 步骤 3
|
||||
|
||||
@ -64,7 +66,7 @@ lspci -vnn | grep VGA
|
||||
|
||||
#### 步骤 4
|
||||
|
||||
要安装所需的驱动,请在终端中输入以下一个命令。下面的命令是用于显卡的命令。根据你的系统进行更新。
|
||||
要安装所需的驱动,请在终端中输入以下一个命令。下面的命令是用于我的显卡的命令。根据你的系统相应调整。
|
||||
|
||||
```
|
||||
sudo dnf install akmod-nvidia sudo dnf install xorg-x11-drv-nvidia-390xx akmod-nvidia-390xx sudo dnf install xorg-x11-drv-nvidia-340xx akmod-nvidia-340xx
|
||||
@ -74,13 +76,13 @@ sudo dnf install akmod-nvidia sudo dnf install xorg-x11-drv-nvidia-390xx akmod-n
|
||||
|
||||
#### 步骤 5
|
||||
|
||||
要使更改生效,请重启系统。你的系统重启可能需要更长的时间,因为它将 Nvidia 驱动注入到 Linux 内核中。
|
||||
要使更改生效,请重启系统。你的系统重启可能需要比较长的时间,因为它将 Nvidia 驱动注入到 Linux 内核中。
|
||||
|
||||
重启并登录系统后,你会看到更好的视觉效果,并且不会出现屏幕撕裂的情况。
|
||||
|
||||
![Fedora with Nvidia drivers][15]
|
||||
|
||||
#### 额外的提示:
|
||||
### 额外的提示
|
||||
|
||||
这是可选步骤,但建议这样做。添加 RPMFusion 仓库时,你可以访问常规仓库中不可用的多媒体包。
|
||||
|
||||
@ -96,7 +98,7 @@ sudo dnf groupupdate multimedia --setop="install_weak_deps=False" --exclude=Pack
|
||||
sudo dnf groupupdate sound-and-video
|
||||
```
|
||||
|
||||
希望本教程对在 Fedora 上安装 Nvidia 驱动很有用。你还想在 It’s FOSS 上看到其他 Fedora 教程吗?
|
||||
希望本教程对在 Fedora 上安装 Nvidia 驱动很有用。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
@ -105,7 +107,7 @@ via: https://itsfoss.com/install-nvidia-drivers-fedora/
|
||||
作者:[John Paul][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
校对:[wxy](https://github.com/wxy)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
@ -1,74 +0,0 @@
|
||||
[#]: collector: (lujun9972)
|
||||
[#]: translator: ( )
|
||||
[#]: reviewer: ( )
|
||||
[#]: publisher: ( )
|
||||
[#]: url: ( )
|
||||
[#]: subject: (My top 5 Ansible modules)
|
||||
[#]: via: (https://opensource.com/article/19/11/ansible-modules)
|
||||
[#]: author: (Mark Phillips https://opensource.com/users/markp)
|
||||
|
||||
My top 5 Ansible modules
|
||||
======
|
||||
Learn how to achieve almost anything with these Ansible modules.
|
||||
![][1]
|
||||
|
||||
When I was growing up, my grandfather had a shed in his garden. He would spend hours in there, making and fixing things. This was way before we had the internet, so I spent a lot of time studying him creating things in that shed. Although the shed was full of many tools, from drills to lathes to electrical gubbins and lots of things I doubt I could identify even today, he made use of only a tiny subset of what he had at hand. Yet there never seemed to be limits to what he could achieve.
|
||||
|
||||
I tell you that story because I feel like my career has been spent in a metaphorical shed. Computers are so many tools, all in a small (virtual?) space. And there are tool sheds within tool sheds—my favourite being Ansible. The recent 2.9 release ships with 3,681 modules! **3,681!** When I first started using Ansible in the summer of 2013, version 1.2.1 had just 113 modules, yet, as [I wrote at the time][2], I could still achieve anything I imagined.
|
||||
|
||||
Modules are the backbone of Ansible, the gears to make light of heavy lifting. They're designed to do one job well, thus realising [the Unix philosophy][3]. This is how we've come to bundle so many of them; Ansible as the conductor of the orchestra now has a lot of instruments at its command.
|
||||
|
||||
Reviewing a Git repository of my Ansible plays and roles over the years reveals that I have used just 35 modules. This small subset was used to build large infrastructures. I wonder what could be achieved with an even smaller subset, though? As I reviewed those 35, I pondered if I could achieve the same results with only five modules at my disposal. So here are my five favourite modules, in a rather tenuous order of precedence.
|
||||
|
||||
### 5. [authorized_key][4]
|
||||
|
||||
Secure shell (SSH) is at the heart of Ansible, at least for almost everything besides Windows. Key (no pun intended) to using SSH efficiently with Ansible is… [keys][5]! Slight aside—there are a lot of very cool things you can do for security with SSH keys. It's worth perusing the **authorized_keys** section of the [sshd manual page][6]. Managing SSH keys can become laborious if you're getting into the realms of granular user access, and although we could do it with either of my next two favourites, I prefer to use the module because it [enables easy management through variables][7].
|
||||
|
||||
### 4. [file][8]
|
||||
|
||||
Besides the obvious function of placing a file somewhere, the **file** module also sets ownership and permissions. I'd say that's a lot of _bang for your buck_ with one module. I'd proffer a substantial portion of security relates to setting permissions too, so the **file** module plays nicely with **authorized_keys**.
|
||||
|
||||
### 3. [template][9]
|
||||
|
||||
There are so many ways to manipulate the contents of files, and I see lots of folk use **[lineinfile][10]**. I've used it myself for small tasks. However, the **template** module is so much clearer because you maintain the entire file for context. My preference is to write Ansible content in such a way that anyone can understand it _easily_—which to me means not making it hard to understand what is happening. Use of **template** means being able to see the entire file you're putting into place, complete with the variables you are using to change pieces.
|
||||
|
||||
### 2. [uri][11]
|
||||
|
||||
Many modules in the current distribution leverage Ansible as an orchestrator. They talk to another service, rather than doing something specific like putting a file into place. Usually, that talking is over HTTP too. In the days before many of these modules existed, you _could_ program an API directly using the **uri** module. It's a powerful access tool, enabling you to do a lot. I wouldn't be without it in my fictitious Ansible shed.
|
||||
|
||||
### 1. [shell][12]
|
||||
|
||||
The joker card in our pack. The Swiss Army Knife. If you're absolutely stuck for how to control something else, use **shell**. Some will argue we're now talking about making Ansible a Bash script—but, I would say it's still better because with the use of the **name** parameter in your plays and roles, you document every step. To me, that's as big a bonus as anything. Back in the days when I was still consulting, I once helped a database administrator (DBA) migrate to Ansible. The DBA wasn't one for change and pushed back at changing working methods. So, to ease into the Ansible way, we called some existing DB management scripts from Ansible using the **shell** module. With an informative **name** statement to accompany the task.
|
||||
|
||||
You can achieve a lot with these five modules. Yes, modules designed to do a specific task will make your life even easier. But with a smidgen of engineering simplicity, you can achieve a lot with very little. Ansible developer Brian Coca is a master at it, and [his tips and tricks talk][13] is always worth a watch.
|
||||
|
||||
* * *
|
||||
|
||||
What do you think about my top five? What five modules would you pick and why, if you were so limited? Let me know in the comments below!
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://opensource.com/article/19/11/ansible-modules
|
||||
|
||||
作者:[Mark Phillips][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://opensource.com/users/markp
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/mandelbrot_set.png?itok=bmPc0np5
|
||||
[2]: http://probably.co.uk/post/puppet-vs-chef-vs-ansible/
|
||||
[3]: https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well
|
||||
[4]: https://docs.ansible.com/ansible/latest/modules/authorized_key_module.html
|
||||
[5]: https://linux.die.net/man/1/ssh-keygen
|
||||
[6]: https://linux.die.net/man/8/sshd
|
||||
[7]: https://github.com/phips/ansible-demos/blob/3bf59df1eb2390b31b5c42333197e2fbb7fec93f/roles/ansible-users/tasks/main.yml#L35
|
||||
[8]: https://docs.ansible.com/ansible/latest/modules/file_module.html
|
||||
[9]: https://docs.ansible.com/ansible/latest/modules/template_module.html
|
||||
[10]: https://docs.ansible.com/ansible/latest/modules/lineinfile_module.html
|
||||
[11]: https://docs.ansible.com/ansible/latest/modules/uri_module.html
|
||||
[12]: https://docs.ansible.com/ansible/latest/modules/shell_module.html
|
||||
[13]: https://www.ansible.com/ansible-tips-and-tricks
|
Loading…
Reference in New Issue
Block a user