博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
金蝶kis可用库存查询_如何建立可用库存
阅读量:2506 次
发布时间:2019-05-11

本文共 15337 字,大约阅读时间需要 51 分钟。

金蝶kis可用库存查询

介绍 (Introduction)

Ansible is a modern configuration management tool that facilitates the task of setting up and maintaining remote servers, with a minimalist design intended to get users up and running quickly. Ansible uses an inventory file to keep track of which hosts are part of your infrastructure, and how to reach them for running commands and playbooks.

Ansible是一种现代的配置管理工具,可简化设置和维护远程服务器的任务,其极简设计旨在使用户快速启动并运行。 Ansible使用清单文件来跟踪哪些主机是您的基础架构的一部分,以及如何访问它们以运行命令和剧本。

There are multiple ways in which you can set up your Ansible inventory file, depending on your environment and project needs. In this guide, we’ll demonstrate how to create inventory files and organize servers into groups and subgroups, how to set up host variables, and how to use patterns to control the execution of Ansible commands and playbooks per host and per group.

根据环境和项目需求,可以通过多种方式设置Ansible库存文件。 在本指南中,我们将演示如何创建清单文件并将服务器组织为组和子组,如何设置主机变量,以及如何使用模式控制每个主机和每个组的Ansible命令和剧本的执行。

先决条件 (Prerequisites)

In order to follow this guide, you’ll need:

为了遵循本指南,您需要:

  • One Ansible control node: an Ubuntu 20.04 machine with Ansible installed and configured to connect to your Ansible hosts using SSH keys. Make sure the control node has a regular user with sudo permissions and a firewall enabled, as explained in our guide. To set up Ansible, please follow our guide on .

    一个Ansible控制节点 :安装了Ansible并配置为使用SSH密钥连接到您的Ansible主机的Ubuntu 20.04计算机。 确保控制节点具有sudo权限的常规用户并启用了防火墙,如“ 指南中所述。 要设置Ansible,请遵循有关指南。

  • Two or more Ansible Hosts: two or more remote Ubuntu 20.04 servers.

    两个或多个Ansible主机 :两个或多个远程Ubuntu 20.04服务器。

第1步-创建自定义清单文件 (Step 1 — Creating a Custom Inventory File)

Upon installation, Ansible creates an inventory file that is typically located at /etc/ansible/hosts. This is the default location used by Ansible when a custom inventory file is not provided with the -i option, during a playbook or command execution.

安装后,Ansible创建一个清单文件,该文件通常位于/etc/ansible/hosts 。 当在剧本或命令执行过程中-i选项未提供自定义清单文件时,这是Ansible使用的默认位置。

Even though you can use this file without problems, using per-project inventory files is a good practice to avoid mixing servers when executing commands and playbooks. Having per-project inventory files will also facilitate sharing your provisioning setup with collaborators, given you include the inventory file within the project’s code repository.

即使您可以毫无问题地使用此文件,使用每个项目的清单文件也是避免在执行命令和剧本时混合服务器的一种好习惯。 如果您将清单文件包含在项目的代码存储库中,则拥有每个项目的清单文件也将有助于与协作者共享您的供应设置。

To get started, access your home folder and create a new directory to hold your Ansible files:

首先,访问您的主文件夹并创建一个新目录来保存您的Ansible文件:

  • cd ~

    光盘〜
  • mkdir ansible

    mkdir ansible

Move to that directory and open a new inventory file using your text editor of choice. Here, we’ll use nano:

移至该目录并使用您选择的文本编辑器打开一个新的清单文件。 在这里,我们将使用nano

  • cd ansible

    光盘
  • nano inventory

    纳米库存

A list of your nodes, with one server per line, is enough for setting up a functional inventory file. Hostnames and IP addresses are interchangeable:

您的节点列表(每行一台服务器)足以设置功能清单文件。 主机名和IP地址可以互换:

~/ansible/inventory
〜/可用/库存
203.0.113.111203.0.113.112203.0.113.113server_hostname

Once you have an inventory file set up, you can use the ansible-inventory command to validate and obtain information about your Ansible inventory:

设置库存文件后,可以使用ansible-inventory命令来验证并获取有关您的Ansible库存的信息:

  • ansible-inventory -i inventory --list

    ansible-inventory -i库存-列表
Output   
{ "_meta": { "hostvars": {} }, "all": { "children": [ "ungrouped" ] }, "ungrouped": { "hosts": [ "203.0.113.111", "203.0.113.112", "203.0.113.113", "server_hostname" ] }}

Even though we haven’t set up any groups within our inventory, the output shows 2 distinct groups that are automatically inferred by Ansible: all and ungrouped. As the name suggests, all is used to refer to all servers from your inventory file, no matter how they are organized. The ungrouped group is used to refer to servers that aren’t listed within a group.

尽管我们还没有建立我们的库存中的任何组,输出显示2个不同的组由Ansible自动推断: allungrouped 。 顾名思义, all用来指代清单文件中的所有服务器,无论它们如何组织。 ungrouped组用于引用未在组内列出的服务器。

使用自定义清单运行命令和剧本 (Running Commands and Playbooks with Custom Inventories)

To run Ansible commands with a custom inventory file, use the -i option as follows:

要对自定义清单文件运行Ansible命令,请使用-i选项,如下所示:

  • ansible all -i inventory -m ping

    ansible all -i库存 -m ping

This would execute the ping module on all hosts listed in your custom inventory file.

这将在自定义清单文件中列出的所有主机上执行ping模块。

Similarly, this is how you execute Ansible playbooks with a custom inventory file:

同样,这是使用自定义清单文件执行Ansible剧本的方法:

  • ansible-playbook -i inventory playbook.yml

    ansible-playbook -i广告资源 playbook.yml

Note: For more information on how to connect to nodes and how to run commands and playbooks, please refer to our guide.

注意 :有关如何连接到节点以及如何运行命令和剧本的更多信息,请参阅我们的“ 指南。

So far, we’ve seen how to create a basic inventory and how to use it for running commands and playbooks. In the next step, we’ll see how to organize nodes into groups and subgroups.

到目前为止,我们已经了解了如何创建基本清单以及如何将其用于运行命令和剧本。 在下一步中,我们将看到如何将节点组织为组和子组。

第2步-将服务器分为组和子组 (Step 2 — Organizing Servers Into Groups and Subgroups)

Within the inventory file, you can organize your servers into different groups and subgroups. Beyond helping to keep your hosts in order, this practice will enable you to use group variables, a feature that can greatly facilitate managing with Ansible.

在清单文件中,您可以将服务器分为不同的组和子组。 除了帮助使主机井井有条之外,这种做法还使您能够使用组变量 ,该功能可以极大地方便使用Ansible管理 。

A host can be part of multiple groups. The following inventory file in INI format demonstrates a setup with four groups: webservers, dbservers, development, and production. You’ll notice that the servers are grouped by two different qualities: their purpose (web and database), and how they’re being used (development and production).

主机可以是多个组的一部分。 以下INI格式的清单文件演示了一个由四组组成的设置: webserversdbserversdevelopmentproduction 。 您会注意到,服务器按两种不同的质量分组:它们的用途(Web和数据库)以及如何使用它们(开发和生产)。

~/ansible/inventory
〜/可用/库存
[webservers]203.0.113.111203.0.113.112[dbservers]203.0.113.113server_hostname[development]203.0.113.111203.0.113.113[production]203.0.113.112server_hostname

If you were to run the ansible-inventory command again with this inventory file, you would see the following arrangement:

如果要对该清单文件再次运行ansible-inventory命令,则会看到以下安排:

Output   
{ "_meta": { "hostvars": {} }, "all": { "children": [ "dbservers", "development", "production", "ungrouped", "webservers" ] }, "dbservers": { "hosts": [ "203.0.113.113", "server_hostname" ] }, "development": { "hosts": [ "203.0.113.111", "203.0.113.113" ] }, "production": { "hosts": [ "203.0.113.112", "server_hostname" ] }, "webservers": { "hosts": [ "203.0.113.111", "203.0.113.112" ] }}

It is also possible to aggregate multiple groups as children under a “parent” group. The “parent” is then called a metagroup. The following example demonstrates another way to organize the previous inventory using metagroups to achieve a comparable, yet more granular arrangement:

也可以聚集在一个“父”组多组儿童 。 然后将“父母”称为元组 。 下面的示例演示了另一种使用元组来组织先前清单的方法,以实现可比的,但更加精细的安排:

~/ansible/inventory
〜/可用/库存
[web_dev]203.0.113.111[web_prod]203.0.113.112[db_dev]203.0.113.113[db_prod]server_hostname[webservers:children]web_devweb_prod[dbservers:children]db_devdb_prod[development:children]web_devdb_dev[production:children]web_proddb_prod

The more servers you have, the more it makes sense to break groups down or create alternative arrangements so that you can target smaller groups of servers as needed.

您拥有的服务器越多,分解组或创建替代安排的意义就越大,以便您可以根据需要定位较小的服务器组。

步骤3 —设置主机别名 (Step 3 — Setting Up Host Aliases)

You can use aliases to name servers in a way that facilitates referencing those servers later, when running commands and playbooks.

您可以使用别名为服务器命名,以方便以后在运行命令和剧本时引用这些服务器。

To use an alias, include a variable named ansible_host after the alias name, containing the corresponding IP address or hostname of the server that should respond to that alias:

要使用别名, ansible_host在别名之后包括一个名为ansible_host的变量,其中包含应响应该别名的服务器的相应IP地址或主机名:

~/ansible/inventory
〜/可用/库存
server1 ansible_host=203.0.113.111server2 ansible_host=203.0.113.112server3 ansible_host=203.0.113.113server4 ansible_host=server_hostname

If you were to run the ansible-inventory command with this inventory file, you would see output similar to this:

如果要对此清单文件运行ansible-inventory命令,则会看到类似以下的输出:

Output   
{ "_meta": { "hostvars": { "server1": { "ansible_host": "203.0.113.111" }, "server2": { "ansible_host": "203.0.113.112" }, "server3": { "ansible_host": "203.0.113.113" }, "server4": { "ansible_host": "server_hostname" } } }, "all": { "children": [ "ungrouped" ] }, "ungrouped": { "hosts": [ "server1", "server2", "server3", "server4" ] }}

Notice how the servers are now referenced by their aliases instead of their IP addresses or hostnames. This makes it easier for targeting individual servers when running commands and playbooks.

注意,现在如何通过服务器的别名而不是其IP地址或主机名来引用服务器。 这使得在运行命令和剧本时更容易定位单个服务器。

步骤4 —设置主机变量 (Step 4 — Setting Up Host Variables)

It is possible to use the inventory file to set up variables that will change Ansible’s default behavior when connecting and executing commands on your nodes. This is in fact what we did in the previous step, when setting up host aliases. The ansible_host variable tells Ansible where to find the remote nodes, in case an alias is used to refer to that server.

可以使用清单文件来设置变量,这些变量将在节点上连接和执行命令时更改Ansible的默认行为。 实际上,这是我们在设置主机别名时在上一步中所做的。 如果使用别名引用该服务器,则ansible_host变量告诉Ansible在哪里可以找到远程节点。

Inventory variables can be set per host or per group. In addition to customizing Ansible’s default settings, these variables are also accessible from your playbooks, which enables further customization for individual hosts and groups.

可以按主机或组设置清单变量。 除了自定义Ansible的默认设置外,还可以从您的剧本中访问这些变量,从而可以进一步为单个主机和组进行自定义。

The following example shows how to define the default remote user when connecting to each of the nodes listed in this inventory file:

以下示例显示了在连接到此清单文件中列出的每个节点时如何定义默认远程用户:

~/ansible/inventory
〜/可用/库存
server1 ansible_host=203.0.113.111 ansible_user=sammyserver2 ansible_host=203.0.113.112 ansible_user=sammyserver3 ansible_host=203.0.113.113 ansible_user=myuserserver4 ansible_host=server_hostname ansible_user=myuser

You could also create a group to aggregate the hosts with similar settings, and then set up their variables at the group level:

您还可以创建一个组来聚合具有相似设置的主机,然后在组级别上设置其变量:

~/ansible/inventory
〜/可用/库存
[group_a]server1 ansible_host=203.0.113.111 server2 ansible_host=203.0.113.112[group_b]server3 ansible_host=203.0.113.113 server4 ansible_host=server_hostname[group_a:vars]ansible_user=sammy[group_b:vars]ansible_user=myuser

This inventory arrangement would generate the following output with ansible-inventory:

这种库存安排将产生以下带有ansible-inventory输出:

Output   
{ "_meta": { "hostvars": { "server1": { "ansible_host": "203.0.113.111", "ansible_user": "sammy" }, "server2": { "ansible_host": "203.0.113.112", "ansible_user": "sammy" }, "server3": { "ansible_host": "203.0.113.113", "ansible_user": "myuser" }, "server4": { "ansible_host": "server_hostname", "ansible_user": "myuser" } } }, "all": { "children": [ "group_a", "group_b", "ungrouped" ] }, "group_a": { "hosts": [ "server1", "server2" ] }, "group_b": { "hosts": [ "server3", "server4" ] }}

Notice that all inventory variables are listed within the _meta node in the JSON output produced by ansible-inventory.

注意,所有清单变量都在_meta ansible-inventory产生的JSON输出的_meta节点中列出。

第5步—使用模式定位命令和剧本的执行 (Step 5 — Using Patterns to Target Execution of Commands and Playbooks)

When executing commands and playbooks with Ansible, you must provide a target. Patterns allow you to target specific hosts, groups, or subgroups in your inventory file. They’re very flexible, supporting regular expressions and wildcards.

使用Ansible执行命令和剧本时,必须提供一个目标。 模式允许您定位清单文件中的特定主机,组或子组。 它们非常灵活,支持正则表达式和通配符。

Consider the following inventory file:

考虑以下清单文件:

~/ansible/inventory
〜/可用/库存
[webservers]203.0.113.111203.0.113.112[dbservers]203.0.113.113server_hostname[development]203.0.113.111203.0.113.113[production]203.0.113.112server_hostname

Now imagine you need to execute a command targeting only the database server(s) that are running on production. In this example, there’s only server_hostname matching that criteria; however, it could be the case that you have a large group of database servers in that group. Instead of individually targeting each server, you could use the following pattern:

现在,假设您需要执行仅针对生产环境中运行的数据库服务器的命令。 在此示例中,只有符合该条件的server_hostname ; 但是,可能是在该组中有大量数据库服务器的情况。 您可以使用以下模式来代替单独定位每个服务器:

  • ansible dbservers:&production -m ping

    ansible dbservers:&生产 -m ping

This pattern would target only servers that are present both in the dbservers as well as in the production groups. If you wanted to do the opposite, targeting only servers that are present in the dbservers but not in the production group, you would use the following pattern instead:

该模式将仅针对dbserversproduction组中都存在的服务器。 如果您想做相反的事情,仅针对dbservers中存在的服务器, 而不针对production组中的服务器,则可以使用以下模式:

  • ansible dbservers:!production -m ping

    ansible dbservers:!production -m ping

The following table contains a few different examples of common patterns you can use when running commands and playbooks with Ansible:

下表包含一些使用Ansible运行命令和剧本时可以使用的常见模式的不同示例:

Pattern Result Target
all All Hosts from your inventory file
host1 A single host (host1)
host1:host2 Both host1 and host2
group1 A single group (group1)
group1:group2 All servers in group1 and group2
group1:&group2 Only servers that are both in group1 and group2
group1:!group2 Servers in group1 except those also in group2
模式 结果目标
all 您清单文件中的所有主机
host1 单个主机( host1 )
host1:host2 host1host2
group1 单个组( group1 )
group1:group2 在所有服务器group1group2
group1:&group2 只有两者都是在服务器group1group2
group1:!group2 服务器在group1 ,除了还可以是group2

For more advanced pattern options, such as using positional patterns and regex to define targets, please refer to the .

有关更高级的模式选项,例如使用位置模式和正则表达式定义目标,请参考的 。

结论 (Conclusion)

In this guide, we had a detailed look into Ansible inventories. We’ve seen how to organize nodes into groups and subgroups, how to set up inventory variables, and how to use patterns to target different groups of servers when running commands and playbooks.

在本指南中,我们详细研究了Ansible库存。 我们已经了解了如何在运行命令和剧本时将节点组织为组和子组,如何设置清单变量,以及如何使用模式将不同的服务器组作为目标。

In the next part of this series, we’ll see how to manage multiple servers with Ansible ad-hoc commands.

在本系列的下一部分中,我们将看到如何使用Ansible ad-hoc命令管理多个服务器。

翻译自:

金蝶kis可用库存查询

转载地址:http://kvhgb.baihongyu.com/

你可能感兴趣的文章
冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
查看>>
并查集
查看>>
sessionStorage
查看>>
代码示例_进程
查看>>
Java中关键词之this,super的使用
查看>>
人工智能暑期课程实践项目——智能家居控制(一)
查看>>
前端数据可视化插件(二)图谱
查看>>
kafka web端管理工具 kafka-manager【转发】
查看>>
获取控制台窗口句柄GetConsoleWindow
查看>>
Linux下Qt+CUDA调试并运行
查看>>
51nod 1197 字符串的数量 V2(矩阵快速幂+数论?)
查看>>
OKMX6Q在ltib生成的rootfs基础上制作带QT库的根文件系统
查看>>
zabbix
查看>>
多线程基础
查看>>
完美解决 error C2220: warning treated as error - no ‘object’ file generated
查看>>
使用SQL*PLUS,构建完美excel或html输出
查看>>
SQL Server数据库笔记
查看>>
X-Forwarded-For伪造及防御
查看>>
android系统平台显示驱动开发简要:LCD驱动调试篇『四』
查看>>
Android 高仿微信头像截取 打造不一样的自定义控件
查看>>