diff --git a/published/20191227 The importance of consistency in your Python code.md b/published/20191227 The importance of consistency in your Python code.md new file mode 100644 index 0000000000..5ff2d11caf --- /dev/null +++ b/published/20191227 The importance of consistency in your Python code.md @@ -0,0 +1,72 @@ +[#]: collector: (lujun9972) +[#]: translator: (stevenzdg988) +[#]: reviewer: (wxy) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-13082-1.html) +[#]: subject: (The importance of consistency in your Python code) +[#]: via: (https://opensource.com/article/19/12/zen-python-consistency) +[#]: author: (Moshe Zadka https://opensource.com/users/moshez) + +Python 代码一致性的重要性 +====== + +> 本文是 Python 之禅特殊系列的一部分,重点是第十二、十三和十四原则:模糊性和明确性的作用。 + +![](https://img.linux.net.cn/data/attachment/album/202102/03/231758po1lcicxmxyjxlba.jpg) + +最小惊喜原则是设计用户界面时的一个 [准则][2]。它是说,当用户执行某项操作时,程序执行的事情应该使用户尽量少地感到意外。这和孩子们喜欢一遍又一遍地读同一本书的原因是一样的:没有什么比能够预测并让预测成真更让人欣慰的了。 + +在开发 [ABC 语言][3](Python 的灵感来源)的过程中,一个重要的见解是,编程设计是用户界面,需要使用与 UI 设计者相同的工具来设计。值得庆幸的是,从那以后,越来越多的语言采用了 UI 设计中的可承受性affordance人体工程学ergonomics的概念,即使它们的应用并不严格。 + +这就引出了 [Python 之禅][4] 中的三个原则。 + +### 面对歧义,要拒绝猜测的诱惑In the face of ambiguity, refuse the temptation to guess + +`1 + "1"` 的结果应该是什么? `"11"` 和 `2` 都是猜测。这种表达方式是*歧义的*:无论如何做都会让一些人感到惊讶。 + +一些语言选择猜测。在 JavaScript 中,结果为 `"11"`。在 Perl 中,结果为 `2`。在 C 语言中,结果自然是空字符串。面对歧义,JavaScript、Perl 和 C 都在猜测。 + +在 Python 中,这会引发 `TypeError`:这不是能忽略的错误。捕获 `TypeError` 是非典型的:它通常将终止程序或至少终止当前任务(例如,在大多数 Web 框架中,它将终止对当前请求的处理)。 + +Python 拒绝猜测 `1 + "1"` 的含义。程序员必须以明确的意图编写代码:`1 + int("1")`,即 `2`;或者 `str(1) + "1"`,即 `"11"`;或 `"1"[1:]`,这将是一个空字符串。通过拒绝猜测,Python 使程序更具可预测性。 + +### 尽量找一种,最好是唯一一种明显的解决方案There should be one—and preferably only one—obvious way to do it + +预测也会出现偏差。给定一个任务,你能预知要实现该任务的代码吗?当然,不可能完美地预测。毕竟,编程是一项具有创造性的任务。 + +但是,不必有意提供多种冗余方式来实现同一目标。从某种意义上说,某些解决方案或许 “更好” 或 “更 Python 化Pythonic”。 + +对 Python 美学欣赏部分是因为,可以就哪种解决方案更好进行健康的辩论。甚至可以持不同观点而继续编程。甚至为使其达成一致,接受不同意的观点也是可以的。但在这一切之下,必须有一种这样的认识,即正确的解决方案终将会出现。我们必须希望,通过商定实现目标的最佳方法,而最终达成真正的一致。 + +### 虽然这种方式一开始可能并不明显(除非你是荷兰人)Although that way may not be obvious at first (unless you're Dutch) + +这是一个重要的警告:首先,实现任务的最佳方法往往*不*明显。观念在不断发展。Python 也在进化。逐块读取文件的最好方法,可能要等到 Python 3.8 时使用 [walrus 运算符][5](`:=`)。 + +逐块读取文件这样常见的任务,在 Python 存在近 *30年* 的历史中并没有 “唯一的最佳方法”。 + +当我在 1998 年从 Python 1.5.2 开始使用 Python 时,没有一种逐行读取文件的最佳方法。多年来,知道字典中是否有某个键的最佳方法是使用关键字 `.haskey`,直到 `in` 操作符出现才发生改变。 + +只是要意识到找到实现目标的一种(也是唯一一种)方法可能需要 30 年的时间来尝试其它方法,Python 才可以不断寻找这些方法。这种历史观认为,为了做一件事用上 30 年是可以接受的,但对于美国这个存在仅 200 多年的国家来说,人们常常会感到不习惯。 + +从 Python 之禅的这一部分来看,荷兰人,无论是 Python 的创造者 [Guido van Rossum][6] 还是著名的计算机科学家 [Edsger W. Dijkstra][7],他们的世界观是不同的。要理解这一部分,某种程度的欧洲人对时间的感受是必不可少的。 + +-------------------------------------------------------------------------------- + +via: https://opensource.com/article/19/12/zen-python-consistency + +作者:[Moshe Zadka][a] +选题:[lujun9972][b] +译者:[stevenzdg988](https://github.com/stevenzdg988) +校对:[wxy](https://github.com/wxy) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://opensource.com/users/moshez +[b]: https://github.com/lujun9972 +[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/rh_003499_01_other11x_cc.png?itok=I_kCDYj0 (Two animated computers waving one missing an arm) +[2]: https://www.uxpassion.com/blog/the-principle-of-least-surprise/ +[3]: https://en.wikipedia.org/wiki/ABC_(programming_language) +[4]: https://www.python.org/dev/peps/pep-0020/ +[5]: https://www.python.org/dev/peps/pep-0572/#abstract +[6]: https://en.wikipedia.org/wiki/Guido_van_Rossum +[7]: http://en.wikipedia.org/wiki/Edsger_W._Dijkstra diff --git a/translated/tech/20201013 My first day using Ansible.md b/published/20201013 My first day using Ansible.md similarity index 69% rename from translated/tech/20201013 My first day using Ansible.md rename to published/20201013 My first day using Ansible.md index 4182d6fa45..990ddc1f24 100644 --- a/translated/tech/20201013 My first day using Ansible.md +++ b/published/20201013 My first day using Ansible.md @@ -1,24 +1,26 @@ [#]: collector: "lujun9972" [#]: translator: "MjSeven" -[#]: reviewer: " " -[#]: publisher: " " -[#]: url: " " +[#]: reviewer: "wxy" +[#]: publisher: "wxy" +[#]: url: "https://linux.cn/article-13079-1.html" [#]: subject: "My first day using Ansible" [#]: via: "https://opensource.com/article/20/10/first-day-ansible" [#]: author: "David Both https://opensource.com/users/dboth" 使用 Ansible 的第一天 ====== -一名系统管理员分享了如何使用 Ansible 在网络中配置计算机并把其带入实际工作的信息和建议。 -![People work on a computer server with devices][1] -无论是第一次还是第五十次,启动并运行一台新的物理或虚拟计算机都非常耗时,而且需要大量的工作。多年来,我一直使用我创建的一系列脚本和 RPM 来安装所需的软件包,并为我喜欢的工具配置选项。这种方法效果很好,简化了我的工作,而且还减少了在键盘上输入命令的时间。 +> 一名系统管理员分享了如何使用 Ansible 在网络中配置计算机并把其带入实际工作的信息和建议。 -我一直在寻找更好的工作方式。近几年来,我一直在听到并且读到有关 [Ansible][2] 的信息,它是一个自动配置和管理系统的强大工具。Ansible 允许系统管理员在一个或多个剧本中为每个主机指定一个特定状态,然后执行使主机进入该状态的所有任务。包括安装或删除各种资源,例如 RPM 或 Apt 软件包、配置和其它文件、用户、组等等。 +![](https://img.linux.net.cn/data/attachment/album/202102/03/105826sn41jj0i8evu19nn.jpg) + +无论是第一次还是第五十次,启动并运行一台新的物理或虚拟计算机都非常耗时,而且需要大量的工作。多年来,我一直使用我创建的一系列脚本和 RPM 来安装所需的软件包,并为我喜欢的工具配置各种选项。这种方法效果很好,简化了我的工作,而且还减少了在键盘上输入命令的时间。 + +我一直在寻找更好的工作方式。近几年来,我一直在听到并且读到有关 [Ansible][2] 的信息,它是一个自动配置和管理系统的强大工具。Ansible 允许系统管理员在一个或多个剧本playbook中为每个主机指定一个特定状态,然后执行各种必要的任务,使主机进入该状态。这包括安装或删除各种资源,例如 RPM 或 Apt 软件包、配置文件和其它文件、用户、组等等。 因为一些琐事,我推迟了很长一段时间学习如何使用它。直到最近,我遇到了一个我认为 Ansible 可以轻松解决的问题。 -这篇文章并不会完整地告诉你如何入门 Ansible,相反,它只是对我遇到的问题和我在一些隐秘的地方发现的信息的做一些记录。我在各种在线讨论和问答小组中找到的有关 Ansible 的许多信息都是错误的。错误范围包括明显的老旧信息(没有任何日期或来源的迹象),还有一些是完全错误的信息。 +这篇文章并不会完整地告诉你如何入门 Ansible,相反,它只是对我遇到的问题和我在一些隐秘的地方发现的信息的做了一些记录。我在各种在线讨论和问答小组中找到的有关 Ansible 的许多信息都是错误的。错误范围包括明显的老旧信息(没有任何日期或来源的迹象),还有一些是完全错误的信息。 本文所介绍的内容是有用的,尽管可能还有其它方法可以完成相同的事情,但我使用的是 Ansible 2.9.13 和 [Python][3] 3.8.5。 @@ -32,13 +34,13 @@ ### 开始 -我读过许多有关 Ansible 的好文章和书籍,但从来没有遇到过“我必须把这个用到工作中”那种情况。但是,现在就是这种情况。 +我读过许多有关 Ansible 的好文章和书籍,但从来没有在“我必须现在就把这个做好!”的情况下读过。而现在 —— 好吧,就是现在! 在重读这些文档时,我发现它们主要是在讨论如何从 GitHub 开始安装并使用 Ansible,这很酷。但是我真的只是想尽快开始,所以我使用 DNF 和 Fedora 仓库中的版本在我的 Fedora 工作站上安装了它,非常简单。 但是后来我开始寻找文件位置,并尝试确定需要修改哪些配置文件、将我的剧本保存在什么位置,甚至一个剧本怎么写以及它的作用,我脑海中有一大堆(到目前为止)悬而未决的问题。 -因此,在没有进一步描述我的困难的情况下,以下是我发现的东西以及促使我继续前进的东西。 +因此,不不需要进一步描述我的困难的情况下,以下是我发现的东西以及促使我继续前进的东西。 ### 配置 @@ -46,9 +48,9 @@ Ansible 的配置文件保存在 `/etc/ansible` 中,这很有道理,因为 ` #### ansible.cfg -在进行文档和线上找到的一些实践练习之后,我遇到了一些有关弃用某些较旧的 Python 文件的警告信息。因此,我在 `ansible.cfg` 中将 `deprecation_warnings` 设置为 `false`,这样那些愤怒的红色警告消息就不会出现了: +在进行了从文档和线上找到的一些实践练习之后,我遇到了一些有关弃用某些较旧的 Python 文件的警告信息。因此,我在 `ansible.cfg` 中将 `deprecation_warnings` 设置为 `false`,这样那些愤怒的红色警告消息就不会出现了: -```bash +``` deprecation_warnings = False ``` @@ -56,28 +58,28 @@ deprecation_warnings = False #### hosts 文件 -与 `/etc/hosts` 文件不同,`hosts` 文件也被称为清单文件,它列出了网络上的主机。此文件允许将主机分组到相关集合中,例如服务器、工作站和任何你所需的名称。这个文件包含帮助和大量示例,所以我在这里就不详细介绍了。但是,有些事情你必须知道。 +与 `/etc/hosts` 文件不同,`hosts` 文件也被称为清单inventory文件,它列出了网络上的主机。此文件允许将主机分组到相关集合中,例如“servers”、“workstations”和任何你所需的名称。这个文件包含帮助和大量示例,所以我在这里就不详细介绍了。但是,有些事情你必须知道。 -主机可以在任何组之外列出,但是组对于识别具有一个或多个共同特征的主机很有帮助。组使用 INI 格式,所以服务器组看起来像这样: +主机也可以列在组之外,但是组对于识别具有一个或多个共同特征的主机很有帮助。组使用 INI 格式,所以服务器组看起来像这样: ``` [servers] server1 server2 -...etc. +...... ``` -这个文件中必须有一个主机名,这样 Ansible 才能对它进行操作。尽管有些子命令允许指定主机名,但除非主机名在 `hosts` 文件中,否则命令会失败。一个主机也可以在多个组中。因此,除了 `[servers]` 组之外,`server1` 也可能是 `[webservers]` 组的成员,还可以是 `[ubuntu]` 组的成员,这样以区别于 Fedora 服务器。 +这个文件中必须有一个主机名,这样 Ansible 才能对它进行操作。即使有些子命令允许指定主机名,但除非主机名在 `hosts` 文件中,否则命令会失败。一个主机也可以放在多个组中。因此,除了 `[servers]` 组之外,`server1` 也可能是 `[webservers]` 组的成员,还可以是 `[ubuntu]` 组的成员,这样以区别于 Fedora 服务器。 -Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `hosts` 文件并在它列出的所有主机上执行定义的任务。Ansible 只会尝试在每个主机上工作一次,不管它出现在多少个组中。这也意味着不需要定义 "all" 组,因为 Ansible 可以确定文件中的所有主机名,并创建自己唯一的主机名列表。 +Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `hosts` 文件并在它列出的所有主机上执行定义的任务。Ansible 只会尝试在每个主机上工作一次,不管它出现在多少个组中。这也意味着不需要定义 `all` 组,因为 Ansible 可以确定文件中的所有主机名,并创建自己唯一的主机名列表。 -另一件需要注意的事情是单个主机的多个条目。我在 DNS 文件中使用 `CNAME` 记录来创建别名,这些别名指向某些主机的 [A 记录][5],这样,我可以将一个主机称为 `host1` 或 `h1` 或 `myhost`。如果你在 `hosts` 文件中为同一主机指定多个主机名,则 Ansible 将尝试在所有这些主机名上执行其任务,它无法知道它们指向同一主机。好消息是,这并不会影响整体结果;它只是多花了一点时间,因为 Ansible在辅助主机名上工作,它会确定所有操作均已执行。 +另一件需要注意的事情是单个主机的多个条目。我在 DNS 文件中使用 `CNAME` 记录来创建别名,这些别名指向某些主机的 [A 记录][5],这样,我可以将一个主机称为 `host1` 或 `h1` 或 `myhost`。如果你在 `hosts` 文件中为同一主机指定多个主机名,则 Ansible 将尝试在所有这些主机名上执行其任务,它无法知道它们指向同一主机。好消息是,这并不会影响整体结果;它只是多花了一点时间,因为 Ansible 会在次要主机名上工作,它会确定所有操作均已执行。 -### Ansible facts +### Ansible 实情 -我阅读过 Ansible 的大多数材料都谈到了 [Ansible facts][6],它是与远程系统相关的数据,包括操作系统、IP 地址、文件系统等等。这些信息可以通过其它方式获得,如 `lshw`、`dmidecode` 或 `/proc` 文件系统等。但是 Ansible 会生成一个包含此信息的 JSON 文件。每次 Ansible 运行时,它都会生成这些数据。在这个数据流中,有大量的信息都是键值对形式:`<"变量名": "值">`。所有这些变量都可以在 Ansible 剧本中使用,理解海量信息的最好方法是亲自实践: +我阅读过 Ansible 的大多数材料都谈到了 Ansible [实情][6]facts,它是与远程系统相关的数据,包括操作系统、IP 地址、文件系统等等。这些信息可以通过其它方式获得,如 `lshw`、`dmidecode` 或 `/proc` 文件系统等。但是 Ansible 会生成一个包含此信息的 JSON 文件。每次 Ansible 运行时,它都会生成这些实情数据。在这个数据流中,有大量的信息,都是以键值对形式出现的:`<"variable-name": "value">`。所有这些变量都可以在 Ansible 剧本中使用,理解大量可用信息的最好方法是实际显示一下: -```bash +``` # ansible -m setup | less ``` @@ -85,23 +87,23 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host ### 模块 -`ansible` 命令使用 `-m` 选项来指定 `setup` 模块。Ansible 已经内置了许多模块,所以你不需要使用 -m。也可以安装许多下载的模块,但是内置模块可以完成我目前项目所需的一切。 +上面的 `ansible` 命令使用 `-m` 选项来指定 `setup` 模块。Ansible 已经内置了许多模块,所以你对这些模块不需要使用 `-m`。也可以安装许多下载的模块,但是内置模块可以完成我目前项目所需的一切。 ### 剧本 -剧本可以放在任何地方。因为我需要以 root 身份运行,所以我将它放在了 `/root/ansible` 下。当我运行 Ansible 时,只要这个目录是当前的工作目录(PWD),它就可以找到我的剧本。Ansible 还有一个选项,用于在运行时指定其它剧本和位置。 +剧本playbook几乎可以放在任何地方。因为我需要以 root 身份运行,所以我将它放在了 `/root/ansible` 下。当我运行 Ansible 时,只要这个目录是当前的工作目录(PWD),它就可以找到我的剧本。Ansible 还有一个选项,用于在运行时指定不同的剧本和位置。 -剧本可以包含注释,但是我看到的文章或书籍很少提及此。作为一个相信记录的系统管理员,我发现使用注释很有帮助。这并不是和任务名称做同样的事情,而是要确定任务组的目的,并确保我以某种方式或顺序记录我做这些事情的原因。当我可能忘记最初的想法时,这可以帮助以后解决调试问题。 +剧本可以包含注释,但是我看到的文章或书籍很少提及此。但作为一个相信记录一切的系统管理员,我发现使用注释很有帮助。这并不是说在注释中做和任务名称同样的事情,而是要确定任务组的目的,并确保我以某种方式或顺序记录我做这些事情的原因。当我可能忘记最初的想法时,这可以帮助以后解决调试问题。 -剧本只是定义主机所需状态的任务集合。在剧本的开头指定主机名或目录组,并定义 Ansible 将在其上运行剧本的主机。 +剧本只是定义主机所需状态的任务集合。在剧本的开头指定主机名或清单组,并定义 Ansible 将在其上运行剧本的主机。 以下是我的一个剧本示例: -```bash +``` ################################################################################ # This Ansible playbook updates Midnight commander configuration files.        # ################################################################################ -\- name: Update midnight commander configuration files +- name: Update midnight commander configuration files   hosts: all     tasks: @@ -149,19 +151,18 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host       mode: 0644       owner: root       group: root -<SNIP> +<截断> ``` 剧本从它自己的名字和它将要操作的主机开始,在本文中,所有主机都在我的 `hosts` 文件中。`tasks` 部分列出了使主机达到所需状态的特定任务。这个剧本从使用 DNF 更新 Midnight Commander 开始(如果它不是最新的版本的话)。下一个任务确保创建所需的目录(如果它们不存在),其余任务将文件复制到合适的位置,这些 `file` 和 `copy` 任务还可以为目录和文件设置所有权和文件模式。 剧本细节超出了本文的范围,但是我对这个问题使用了一点蛮力。还有其它方法可以确定哪些用户需要更新文件,而不是对每个用户的每个文件使用一个任务。我的下一个目标是简化这个剧本,使用一些更先进的技术。 -运行剧本很容易,只需要使用 `ansible-playbook` 命令。.yml 扩展名代表 YAML,我看到过它的几种不同含义,但我认为它是“另一种标记语言”,尽管有些人声称 YAML 不是这种语言。 +运行剧本很容易,只需要使用 `ansible-playbook` 命令。`.yml` 扩展名代表 YAML,我看到过它的几种不同含义,但我认为它是“另一种标记语言Yet Another Markup Language”,尽管有些人声称 YAML 不是这种语言。 这个命令将会运行剧本,它会更新 Midnight Commander 文件: - -```bash +``` # ansible-playbook -f 10 UpdateMC.yml ``` @@ -171,12 +172,11 @@ Ansible 很智能。如果 `all` 参数用作主机名,Ansible 会扫描 `host 剧本运行时会列出每个任务和执行结果。`ok` 代表任务管理的机器状态已经完成,因为在任务中定义的状态已经为真,所以 Ansible 不需要执行任何操作。 -`changed` 表示 Ansible 已经执行了指定的任务。在这种情况下,任务中定义的机器状态不为真,所以执行指定的操作使其为真。在彩色终端上,`TASK` 线会显示彩色。在我的咖啡色终端的主机上,`TASK` 线显示为琥珀色,`changed` 是棕色,`ok` 为绿色,错误是红色。 +`changed` 表示 Ansible 已经执行了指定的任务。在这种情况下,任务中定义的机器状态不为真,所以执行指定的操作使其为真。在彩色终端上,`TASK` 行会以彩色显示。我的终端配色为“amber-on-black”,`TASK` 行显示为琥珀色,`changed` 是棕色,`ok` 为绿色,错误是红色。 下面的输出是我最终用于在新主机执行安装后配置的剧本: - -```bash +``` PLAY [Post-installation updates, package installation, and configuration] TASK [Gathering Facts] @@ -205,16 +205,16 @@ changed: [testvm2] => (item=/root/ansible/PostInstallMain/files/MidnightComma TASK [create ~/.config/mc directory in /etc/skel] changed: [testvm2] -<SNIP> +<截断> ``` ### cowsay -如果你的计算机上安装了 [cowsay][7] 程序,你会发现 `TASK` 的名字出现在奶牛的语音泡泡中: +如果你的计算机上安装了 [cowsay][7] 程序,你会发现 `TASK` 的名字出现在奶牛的语音泡泡中: ```  ____________________________________ -< TASK [Ensure we have connectivity] > +< TASK [Ensure we have connectivity] >  ------------------------------------         \   ^__^          \  (oo)\\_______ @@ -244,19 +244,19 @@ changed: [testvm2]     └── UpdateMC.yml ``` -你可以使用任何结构。但是请注意,其它系统管理员可能需要使用你设置的剧本来工作,所以目录应该具有一定程度的逻辑。当我使用 RPM 和 Bash 脚本执行安装任务后,我的文件仓库有点分散,而且绝对没有任何逻辑结构。当我为许多管理任务创建剧本时,我将介绍一个更有逻辑的结构来管理我的目录。 +你可以使用任何结构。但是请注意,其它系统管理员可能需要使用你设置的剧本来工作,所以目录应该具有一定程度的逻辑。当我使用 RPM 和 Bash 脚本执行安装任务后,我的文件仓库有点分散,绝对没有任何逻辑结构。当我为许多管理任务创建剧本时,我将介绍一个更有逻辑的结构来管理我的目录。 -### 多个剧本运行 +### 多次运行剧本 根据需要或期望多次运行剧本是安全的。只有当主机状态与任务中指定的状态不匹配时,才会执行每个任务。这使得很容易从先前的剧本运行中遇到的错误中恢复。因为当剧本遇到错误时,它将停止运行。 -在测试我的第一个剧本时,我犯了很多错误并改正了它们。假设我的修正正确,那么剧本每次运行,都会跳过那些状态已与指定状态匹配的任务,执行不匹配状态的任务。当我的修复程序起作用时,前面失败的任务将成功完成,并且会执行此任务之后的任务--直到遇到另一个错误。 +在测试我的第一个剧本时,我犯了很多错误并改正了它们。假设我的修正正确,那么剧本每次运行,都会跳过那些状态已与指定状态匹配的任务,执行不匹配状态的任务。当我的修复程序起作用时,之前失败的任务就会成功完成,并且会执行此任务之后的任务 —— 直到遇到另一个错误。 这使得测试变得容易。我可以添加新任务,并且在运行剧本时,只有新任务会被执行,因为它们是唯一与测试主机期望状态不匹配的任务。 -### 一些想法 +### 一些思考 -有些任务不适合用 Ansible,因为有更好的方法可以实现特定的计算机状态。我想到的场景是使 VM 返回到初始状态,以便可以多次使用它来执行从已知状态开始的测试。让 VM 进入特定状态,然后对此时的计算机状态进行快照要容易得多。还原到该快照通常比 Ansible 将主机返回到之前状态相比,还原到快照通常会更容易且更快。在研究文章或测试新代码时,我每天都会做几次这样的事情。 +有些任务不适合用 Ansible,因为有更好的方法可以实现特定的计算机状态。我想到的场景是使 VM 返回到初始状态,以便可以多次使用它来执行从已知状态开始的测试。让 VM 进入特定状态,然后对此时的计算机状态进行快照要容易得多。还原到该快照与 Ansible 将主机返回到之前状态相比,通常还原到快照通常会更容易且更快。在研究文章或测试新代码时,我每天都会做几次这样的事情。 在完成用于更新 Midnight Commander 的剧本之后,我创建了一个新的剧本,用于在新安装的 Fedora 主机上执行安装任务。我已经取得了不错的进步,剧本比我第一个的更加复杂,但没有那么粗暴。 @@ -268,7 +268,7 @@ changed: [testvm2] 我找到的最完整、最有用的参考文档是 Ansible 网站上的[用户指南][9]。本文仅供参考,不作为入门文档。 -多年来,Opensource.com 已经发布了许多[有关 Ansible 的文章][10],我发现其中大多数对我的需求很有帮助。Enable Sysadmin 网站上也有很多对我有帮助 [Ansible 文章][11]。你可以通过查看本周(2020 年 10 月 13 日至 14 日)的 [AnsibleFest][12] 了解更多信息。该活动完全是虚拟的,可以免费注册。 +多年来,我们已经发布了许多[有关 Ansible 的文章][10],我发现其中大多数对我的需求很有帮助。Enable Sysadmin 网站上也有很多对我有帮助 [Ansible 文章][11]。你可以通过查看本周(2020 年 10 月 13 日至 14 日)的 [AnsibleFest][12] 了解更多信息。该活动完全是线上的,可以免费注册。 -------------------------------------------------------------------------------- @@ -277,7 +277,7 @@ via: https://opensource.com/article/20/10/first-day-ansible 作者:[David Both][a] 选题:[lujun9972][b] 译者:[MjSeven](https://github.com/MjSeven) -校对:[校对者ID](https://github.com/校对者ID) +校对:[wxy](https://github.com/wxy) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/translated/tech/20210125 Use Joplin to find your notes faster.md b/published/20210125 Use Joplin to find your notes faster.md similarity index 78% rename from translated/tech/20210125 Use Joplin to find your notes faster.md rename to published/20210125 Use Joplin to find your notes faster.md index 212025a919..13e6be8bdf 100644 --- a/translated/tech/20210125 Use Joplin to find your notes faster.md +++ b/published/20210125 Use Joplin to find your notes faster.md @@ -1,28 +1,30 @@ [#]: collector: (lujun9972) [#]: translator: (geekpi) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) +[#]: reviewer: (wxy) +[#]: publisher: (wxy) +[#]: url: (https://linux.cn/article-13080-1.html) [#]: subject: (Use Joplin to find your notes faster) [#]: via: (https://opensource.com/article/21/1/notes-joplin) [#]: author: (Kevin Sonney https://opensource.com/users/ksonney) 使用 Joplin 更快地找到你的笔记 ====== -在多个手写和数字平台上整理笔记是一个严峻的挑战。这里有一个小技巧,可以更好地组织你的笔记,并快速找到你需要的东西。 -![Working from home at a laptop][1] + +> 在多个手写和数字平台上整理笔记是一个严峻的挑战。这里有一个小技巧,可以更好地组织你的笔记,并快速找到你需要的东西。 + +![](https://img.linux.net.cn/data/attachment/album/202102/03/120141dkiqil1vlqiz6wql.jpg) 在前几年,这个年度系列涵盖了单个的应用。今年,我们除了关注 2021 年的策略外,还将关注一体化解决方案。欢迎来到 2021 年 21 天生产力的第十五天。 -保持生产力也意味着(在某种程度上)要有足够的组织能力,以便找到笔记并在需要时参考它们。这不仅是对我自己的挑战,也是我交谈的很多人的挑战。 +保持生产力也意味着(在某种程度上)要有足够的组织能力,以便找到笔记并在需要时参考它们。这不仅是对我自己的挑战,也是与我交谈的很多人的挑战。 -多年来,我在应用中单独或使用数字笔记、纸质笔记、便签、数字便签、word 文档、纯文本文件以及一堆我忘记的其他格式的组合。这不仅让寻找笔记变得困难,而且知道把它们放在哪里是一个更大的挑战。 +多年来,我在应用中单独或使用数字笔记、纸质笔记、便签、数字便签、Word 文档、纯文本文件以及一堆我忘记的其他格式的组合。这不仅让寻找笔记变得困难,而且知道把它们放在哪里是一个更大的挑战。 ![Stacks of paper notes on a desk][2] -一堆笔记 (Jessica Cherry, [CC BY-SA 4.0][3]) +*一堆笔记 (Jessica Cherry, [CC BY-SA 4.0][3])* -还有就是做笔记最重要的一点:如果你以后找不到它,笔记就没有任何价值。知道含有你所需信息的笔记存在于你保存笔记的_某处_,根本没有任何帮助。 +还有就是做笔记最重要的一点:如果你以后找不到它,笔记就没有任何价值。知道含有你所需信息的笔记存在于你保存笔记的*某处*,根本没有任何帮助。 我是如何为自己解决这个问题的呢?正如他们所说,这是一个过程,我希望这也是一个对其他人有效的过程。 @@ -30,13 +32,13 @@ ![Man holding a binder full of notes][4] -三年多的笔记 (Kevin Sonney, [CC BY-SA 4.0][3]) +*三年多的笔记 (Kevin Sonney, [CC BY-SA 4.0][3])* -为了保存我的数字笔记,我需要将它们全部集中到一个地方。这个工具需要能够从多种设备上访问,具有有用的搜索功能,并且能够导出或共享我的笔记。在尝试了很多很多不同的选项之后,我选择了 [Joplin][5]。Joplin 可以让我用 markdown 写笔记,有一个相当不错的搜索功能,有适用于所有操作系统(包括手机)的应用,并支持几种不同的设备同步方式。另外,它还有文件夹_和_标签,因此我可以按照对我有意义的方式将笔记分组。 +为了保存我的数字笔记,我需要将它们全部集中到一个地方。这个工具需要能够从多种设备上访问,具有有用的搜索功能,并且能够导出或共享我的笔记。在尝试了很多很多不同的选项之后,我选择了 [Joplin][5]。Joplin 可以让我用 Markdown 写笔记,有一个相当不错的搜索功能,有适用于所有操作系统(包括手机)的应用,并支持几种不同的设备同步方式。另外,它还有文件夹*和*标签,因此我可以按照对我有意义的方式将笔记分组。 ![Organized Joplin notes management page][6] -我的 Joplin +*我的 Joplin* 我花了一些时间才把所有的东西都放在我想要的地方,但最后,这真的是值得的。现在,我可以找到我所做的笔记,而不是让它们散落在我的办公室、不同的机器和各种服务中。 @@ -47,7 +49,7 @@ via: https://opensource.com/article/21/1/notes-joplin 作者:[Kevin Sonney][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/) 荣誉推出 diff --git a/sources/tech/20190221 Testing Bash with BATS.md b/sources/tech/20190221 Testing Bash with BATS.md index 16c65b2670..1499b811e7 100644 --- a/sources/tech/20190221 Testing Bash with BATS.md +++ b/sources/tech/20190221 Testing Bash with BATS.md @@ -1,5 +1,5 @@ [#]: collector: (lujun9972) -[#]: translator: ( ) +[#]: translator: (stevenzdg988) [#]: reviewer: ( ) [#]: publisher: ( ) [#]: url: ( ) @@ -245,7 +245,7 @@ via: https://opensource.com/article/19/2/testing-bash-bats 作者:[Darin London][a] 选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) +译者:[stevenzdg988](https://github.com/stevenzdg988) 校对:[校对者ID](https://github.com/校对者ID) 本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 diff --git a/sources/tech/20210111 7 Bash tutorials to enhance your command line skills in 2021.md b/sources/tech/20210111 7 Bash tutorials to enhance your command line skills in 2021.md deleted file mode 100644 index b0a6f04d2a..0000000000 --- a/sources/tech/20210111 7 Bash tutorials to enhance your command line skills in 2021.md +++ /dev/null @@ -1,68 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: ( ) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (7 Bash tutorials to enhance your command line skills in 2021) -[#]: via: (https://opensource.com/article/21/1/bash) -[#]: author: (Jim Hall https://opensource.com/users/jim-hall) - -7 Bash tutorials to enhance your command line skills in 2021 -====== -Bash is the default command line shell on most Linux systems. So why not -learn how to get the most out of it? -![Terminal command prompt on orange background][1] - -Bash is the default command line shell on most Linux systems. So why not learn how to get the most out of it? This year, Opensource.com featured many great articles to help you leverage the power of the Bash shell. These are some of the most-read articles about Bash: - -## [Read and write data from anywhere with redirection in the Linux terminal][2] - -Redirection of input and output is a natural function of any programming or scripting language. Technically, it happens inherently whenever you interact with a computer. Input gets read from stdin (standard input, usually your keyboard or mouse), output goes to stdout (standard output, a text or data stream), and errors get sent to stderr. Understanding that these data streams exist enables you to control where information goes when you're using a shell such as Bash. Seth Kenlon shared these great tips to get data from one place to another without a lot of mouse moving and key pressing. You may not use redirection often, but learning to use it can save you a lot of time needlessly opening files and copying and pasting data. - -## [Get started with Bash scripting for sysadmins][3] - -Bash is free and open source software, so anyone can install it, whether they run Linux, BSD, OpenIndiana, Windows, or macOS. Seth Kenlon helps you learn the commands and features that make Bash one of the most powerful shells available. - -## [Try this Bash script for large filesystems][4] - -Have you ever wanted to list all the files in a directory, but just the files, nothing else? How about only the directories? If you have, then Nick Clifton's article might be just what you're looking for. Nick shares a nifty Bash script that can list directories, files, links, or executables. The script works by using the **find** command to do the searching, and then it runs **ls** to show details. It's a clever solution for anyone managing a large Linux system. - -## [Screenshot your Linux system configuration with Bash tools][5] - -There are many reasons you might want to share your Linux configuration with other people. You might be looking for help troubleshooting a problem on your system, or maybe you're so proud of the environment you've created that you want to showcase it to fellow open source enthusiasts. Don Watkins shows us screenFetch and Neofetch to capture and share your system configuration. - -## [6 Handy Bash scripts for Git][6] - -Git has become a ubiquitous code management system. Knowing how to manage a Git repository can streamline your development experience. Bob Peterson shares six Bash scripts that will make your life easier when you're working with Git repositories. **gitlog** prints an abbreviated list of current patches against the master version. Variations of the script can show the patch SHA1 IDs or search for a string within a collection of patches. - -## [5 ways to improve your Bash scripts][7] - -A system admin often writes Bash scripts, some short and some quite lengthy, to accomplish various tasks. Alan Formy-Duval explains how you can make your Bash scripts simpler, more robust, and easier to read and debug. We might assume that we need to employ languages, such as Python, C, or Java, for higher functionality, but that's not necessarily true. The Bash scripting language is very powerful. There is a lot to learn to maximize its usefulness. - -## [My favorite Bash hacks][8] - -Katie McLaughlin helps you improve your productivity with aliases and other shortcuts for the things you forget too often. When you work with computers all day, it's fantastic to find repeatable commands and tag them for easy use later on. Katie's summary of useful Bash features and helper commands to save you time. - -These Bash tips take an already powerful shell to a whole new level of usefulness. Feel free to share your own tips, too. - --------------------------------------------------------------------------------- - -via: https://opensource.com/article/21/1/bash - -作者:[Jim Hall][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/jim-hall -[b]: https://github.com/lujun9972 -[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/terminal_command_linux_desktop_code.jpg?itok=p5sQ6ODE (Terminal command prompt on orange background) -[2]: https://opensource.com/article/20/6/redirection-bash -[3]: https://opensource.com/article/20/4/bash-sysadmins-ebook -[4]: https://opensource.com/article/20/2/script-large-files -[5]: https://opensource.com/article/20/1/screenfetch-neofetch -[6]: https://opensource.com/article/20/1/bash-scripts-git -[7]: https://opensource.com/article/20/1/improve-bash-scripts -[8]: https://opensource.com/article/20/1/bash-scripts-aliases diff --git a/sources/tech/20210120 Learn JavaScript by writing a guessing game.md b/sources/tech/20210120 Learn JavaScript by writing a guessing game.md deleted file mode 100644 index a285bf45cf..0000000000 --- a/sources/tech/20210120 Learn JavaScript by writing a guessing game.md +++ /dev/null @@ -1,300 +0,0 @@ -[#]: collector: (lujun9972) -[#]: translator: (amwps290) -[#]: reviewer: ( ) -[#]: publisher: ( ) -[#]: url: ( ) -[#]: subject: (Learn JavaScript by writing a guessing game) -[#]: via: (https://opensource.com/article/21/1/learn-javascript) -[#]: author: (Mandy Kendall https://opensource.com/users/mkendall) - -Learn JavaScript by writing a guessing game -====== -Take the first steps toward creating interactive, dynamic web content by -practicing some basic JavaScript concepts with a simple game. -![Javascript code close-up with neon graphic overlay][1] - -It's pretty safe to say that most of the modern web would not exist without [JavaScript][2]. It's one of the three standard web technologies (along with HTML and CSS) and allows anyone to create much of the interactive, dynamic content we have come to expect in our experiences with the World Wide Web. From frameworks like [React][3] to data visualization libraries like [D3][4], it's hard to imagine the web without it. - -There's a lot to learn, and a great way to begin learning this popular language is by writing a simple application to become familiar with some concepts. Recently, some Opensource.com correspondents have written about how to learn their favorite language by writing a simple guessing game, so that's a great place to start! - -### Getting started - -JavaScript comes in many flavors, but I'll start with the basic version, commonly called "Vanilla JavaScript." JavaScript is primarily a client-side scripting language, so it can run in any standard browser without installing anything. All you need is a code editor ([Brackets][5] is a great one to try) and the web browser of your choice. - -### HTML user interface - -JavaScript runs in a web browser and interacts with the other standard web technologies, HTML and CSS. To create this game, you'll first use HTML (Hypertext Markup Language) to create a simple interface for your players to use. In case you aren't familiar, HTML is a markup language used to provide structure to content on the web. - -To start, create an HTML file for your code. The file should have the `.html` extension to let the browser know that it is an HTML document. You can call your file `guessingGame.html`. - -Use a few basic HTML tags in this file to display the game's title, instructions for how to play, interactive elements for the player to use to enter and submit their guesses, and a placeholder for providing feedback to the player: - - -``` -<!DOCTYPE> -  <[html][6]> -    <[head][7]> -      <[meta][8] charset="UTF-8" /> -      <[title][9]> JavaScript Guessing Game </[title][9]> -    </[head][7]> -    <[body][10]> -      <[h1][11]>Guess the Number!</[h1][11]> -      <[p][12]>I am thinking of a number between 1 and 100. Can you guess what it is?</[p][12]> -    -      <[label][13] for="guess">My Guess</[label][13]> -      <[input][14] type="number" id="guess"> -      <[input][14] type="submit" id="submitGuess" value="Check My Guess"> -    -      <[p][12] id="feedback"></[p][12]> -    </[body][10]> -  </[html][6]> -``` - -The `

` and `

` elements let the browser know what type of text to display on the page. The set of `

` tags signifies that the text between those two tags (`Guess the Number!`) is a heading. The set of `

` tags that follow signify that the short block of text with the instructions is a paragraph. The empty set of `

` tags at the end of this code block serve as a placeholder for the feedback the game will give the player based on their guess. - -### The <script> tag - -There are many ways to include JavaScript in a web page, but for a short script like this one, you can use a set of `