From b910835b119a8c5370ddc9f53d7e53e389afe3c4 Mon Sep 17 00:00:00 2001
From: Xingyu Wang <xingyu.wang@gmail.com>
Date: Thu, 6 Jun 2019 08:29:15 +0800
Subject: [PATCH 1/2] PRF:20190517 Using Testinfra with Ansible to verify
 server state.md

@geekpi
---
 ...fra with Ansible to verify server state.md | 42 +++++++++----------
 1 file changed, 19 insertions(+), 23 deletions(-)

diff --git a/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md b/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md
index c0c631ccd2..98861a65b7 100644
--- a/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md	
+++ b/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md	
@@ -1,6 +1,6 @@
 [#]: collector: (lujun9972)
 [#]: translator: (geekpi)
-[#]: reviewer: ( )
+[#]: reviewer: (wxy)
 [#]: publisher: ( )
 [#]: url: ( )
 [#]: subject: (Using Testinfra with Ansible to verify server state)
@@ -9,17 +9,18 @@
 
 使用 Testinfra 和 Ansible 验证服务器状态
 ======
-Testinfra 是一个功能强大的库,可用于编写测试来验证基础设施的状态。另外与 Ansible 和 Nagios 相结合,提供了一个用于架构即代码  (IaC)  的简单解决方案。
+
+> Testinfra 是一个功能强大的库,可用于编写测试来验证基础设施的状态。另外它与 Ansible 和 Nagios 相结合,提供了一个用于架构即代码  (IaC)  的简单解决方案。
+
 ![Terminal command prompt on orange background][1]
 
-根据设计,[Ansible][2] 传递机器的期望状态,以确保 Ansible playbook 或角色的内容部署到目标机器上。但是,如果你需要确保所有基础架构更改都在 Ansible 中,该怎么办?或者随时验证服务器的状态?
+根据设计,[Ansible][2] 传递机器的期望状态,以确保 Ansible 剧本或角色的内容部署到目标机器上。但是,如果你需要确保所有基础架构更改都在 Ansible 中,该怎么办?或者想随时验证服务器的状态?
 
 [Testinfra][3] 是一个基础架构测试框架,它可以轻松编写单元测试来验证服务器的状态。它是一个 Python 库,使用强大的 [pytest][4] 测试引擎。
 
 ### 开始使用 Testinfra
 
-可以使用 Python 包管理器 (pip) 和 Python 虚拟环境轻松安装 Testinfra。
-
+可以使用 Python 包管理器(`pip`)和 Python 虚拟环境轻松安装 Testinfra。
 
 ```
 $ python3 -m venv venv
@@ -27,8 +28,7 @@ $ source venv/bin/activate
 (venv) $ pip install testinfra
 ```
 
-Testinfra 也可以使用 EPEL 仓库的 Fedora 和 CentOS 中使用。例如,在 CentOS 7 上,你可以使用以下命令安装它:
-
+Testinfra 也可以通过 Fedora 和 CentOS 的 EPEL 仓库中使用。例如,在 CentOS 7 上,你可以使用以下命令安装它:
 
 ```
 $ yum install -y epel-release
@@ -37,8 +37,7 @@ $ yum install -y python-testinfra
 
 #### 一个简单的测试脚本
 
-在 Testinfra 中编写测试很容易。使用你选择的代码编辑器,将以下内容添加到名为 **test_simple.py** 的文件中:
-
+在 Testinfra 中编写测试很容易。使用你选择的代码编辑器,将以下内容添加到名为 `test_simple.py` 的文件中:
 
 ```
 import testinfra
@@ -50,11 +49,10 @@ def test_sshd_inactive(host):
     assert host.service("sshd").is_running is False
 ```
 
-默认情况下,Testinfra 为测试用例提供了一个主机对象,该对象能访问不同的辅助模块。例如,第一个测试使用 **file** 模块来验证主机上文件的内容,第二个测试用例使用 **service** 模块来检查 systemd 服务的状态。
+默认情况下,Testinfra 为测试用例提供了一个 `host` 对象,该对象能访问不同的辅助模块。例如,第一个测试使用 `file` 模块来验证主机上文件的内容,第二个测试用例使用 `service` 模块来检查 systemd 服务的状态。
 
 要在本机运行这些测试,请执行以下命令:
 
-
 ```
 (venv)$ pytest test_simple.py
 ================================ test session starts ================================
@@ -71,10 +69,9 @@ test_simple.py ..
 
 ### Testinfra 和 Ansible
 
-Testinfra 支持的后端之一是 Ansible,这意味着 Testinfra 可以直接使用 Ansible 的 inventory 文件和 inventory 中定义的一组机器来对它们进行测试。
-
-我们使用以下 inventory 文件作为示例:
+Testinfra 支持的后端之一是 Ansible,这意味着 Testinfra 可以直接使用 Ansible 的清单文件和清单中定义的一组机器来对它们进行测试。
 
+我们使用以下清单文件作为示例:
 
 ```
 [web]
@@ -85,8 +82,7 @@ app-frontend02
 db-backend01
 ```
 
-我们希望确保我们的 Apache Web 服务器在 **app-frontend01** 和 **app-frontend02** 上运行。让我们在名为 **test_web.py** 的文件中编写测试:
-
+我们希望确保我们的 Apache Web 服务器在 `app-frontend01` 和 `app-frontend02` 上运行。让我们在名为 `test_web.py` 的文件中编写测试:
 
 ```
 def check_httpd_service(host):
@@ -102,11 +98,11 @@ def check_httpd_service(host):
 (venv) $ py.test --hosts=web --ansible-inventory=inventory --connection=ansible test_web.py
 ```
 
-在调用测试时,我们使用 Ansible inventory 的 **[web]** 组作为目标计算机,并指定我们要使用 Ansible 作为连接后端。
+在调用测试时,我们使用 Ansible 清单文件的 `[web]` 组作为目标计算机,并指定我们要使用 Ansible 作为连接后端。
 
 #### 使用 Ansible 模块
 
-Testinfra 还为 Ansible 提供了一个很好的可用于测试的 API。该 Ansible 模块能够在 测试中运行 Ansible play,并且能够轻松检查 play 的状态。
+Testinfra 还为 Ansible 提供了一个很好的可用于测试的 API。该 Ansible 模块能够在测试中运行 Ansible 动作,并且能够轻松检查动作的状态。
 
 ```
 def check_ansible_play(host):
@@ -117,15 +113,15 @@ def check_ansible_play(host):
     assert not host.ansible("package", "name=httpd state=present")["changed"]
 ```
 
-B默认情况下,Ansible 的[检查模式][6]已启用,这意味着 Ansible 将报告在远程主机上执行 play 时会发生的变化。
+默认情况下,Ansible 的[检查模式][6]已启用,这意味着 Ansible 将报告在远程主机上执行动作时会发生的变化。
 
 ### Testinfra 和 Nagios
 
-现在我们可以轻松地运行测试来验证机器的状态,我们可以使用这些测试来触发监控系统上的警报。这是捕获意外更改的好方法。
+现在我们可以轻松地运行测试来验证机器的状态,我们可以使用这些测试来触发监控系统上的警报。这是捕获意外的更改的好方法。
 
-Testinfra 提供了与 [Nagios][7] 的集成,它是一种流行的监控解决方案。默认情况下,Nagios 使用 [NRPE][8] 插件对远程主机进行检查,但使用 Testinfra 可以直接从 Nagios master 上运行测试。
+Testinfra 提供了与 [Nagios][7] 的集成,它是一种流行的监控解决方案。默认情况下,Nagios 使用 [NRPE][8] 插件对远程主机进行检查,但使用 Testinfra 可以直接从 Nagios 主控节点上运行测试。
 
-要使 Testinfra 输出与 Nagios 兼容,我们必须在触发测试时使用 **\--nagios** 标志。我们还使用 **-qq** 这个 pytest 标志来启用 pytest 的**静默**模式,这样就不会显示所有测试细节。
+要使 Testinfra 输出与 Nagios 兼容,我们必须在触发测试时使用 `--nagios` 标志。我们还使用 `-qq` 这个 pytest 标志来启用 pytest 的静默模式,这样就不会显示所有测试细节。
 
 ```
 (venv) $ py.test --hosts=web --ansible-inventory=inventory --connection=ansible --nagios -qq line test.py
@@ -141,7 +137,7 @@ via: https://opensource.com/article/19/5/using-testinfra-ansible-verify-server-s
 作者:[Clement Verna][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/) 荣誉推出
 

From 11323348c00428f52f2e80e557447e1e4a33fc2a Mon Sep 17 00:00:00 2001
From: Xingyu Wang <xingyu.wang@gmail.com>
Date: Thu, 6 Jun 2019 08:29:43 +0800
Subject: [PATCH 2/2] PUB:20190517 Using Testinfra with Ansible to verify
 server state.md

@geekpi https://linux.cn/article-10943-1.html
---
 ...517 Using Testinfra with Ansible to verify server state.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
 rename {translated/tech => published}/20190517 Using Testinfra with Ansible to verify server state.md (98%)

diff --git a/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md b/published/20190517 Using Testinfra with Ansible to verify server state.md
similarity index 98%
rename from translated/tech/20190517 Using Testinfra with Ansible to verify server state.md
rename to published/20190517 Using Testinfra with Ansible to verify server state.md
index 98861a65b7..9b2dc01e26 100644
--- a/translated/tech/20190517 Using Testinfra with Ansible to verify server state.md	
+++ b/published/20190517 Using Testinfra with Ansible to verify server state.md	
@@ -1,8 +1,8 @@
 [#]: collector: (lujun9972)
 [#]: translator: (geekpi)
 [#]: reviewer: (wxy)
-[#]: publisher: ( )
-[#]: url: ( )
+[#]: publisher: (wxy)
+[#]: url: (https://linux.cn/article-10943-1.html)
 [#]: subject: (Using Testinfra with Ansible to verify server state)
 [#]: via: (https://opensource.com/article/19/5/using-testinfra-ansible-verify-server-state)
 [#]: author: (Clement Verna https://opensource.com/users/cverna/users/paulbischoff/users/dcritch/users/cobiacomm/users/wgarry155/users/kadinroob/users/koreyhilpert)