[webservers]
site01
site02
site01-dr
[production]
site01
site02
db01
bastion
Once you have placed your hosts in the Ansible inventory, you can start running
commands against them. Ansible includes a module called ping that lets you
test connectivity between yourself and the host. Let's use Ansible from the command
line against one of our machines to confirm that we can configure them.
Ansible was designed to be and one of the ways the developers have done
this is by using SSH to connect to the managed machines. It then sends the code over
the SSH connection and executes it. This means that you don't need to have Ansible
installed on the managed machine. It also means that Ansible can use the same
channels that you are already using to administer the machine.
First, we check connectivity to our server to be configured using the Ansible ping
module. This module simply connects to the following server:
$ ansible site01 -u root -k -m ping
This should ask for the SSH password and then produce a result that looks like the
following code:
site01 | success >> {
"changed": false,
"ping": "pong"
}
If you have an SSH key set up for the remote system, you will be able to leave off the
-k argument to skip the prompt and use the keys. You can also configure Ansible to
use a particular username all the time by either configuring it in the inventory on a
per host basis or in the global Ansible configuration.
To set the username globally, edit /etc/ansible/ansible.cfg and change the line
that sets remote_user in the [defaults] section. You can also change remote_port
to change the default port that Ansible will SSH to. These will change the default
settings for all the machines, but they can be overridden in the inventory file on a per
server or per group basis.
一旦你把主机放到设备清单之后,你就可以运行关于他们的命令了。Ansible中有一个自带的模块叫ping可以用来检查控制设备和受管机器之间的连接性,下面我们就在我们的清单中的主机上运行命令行工具。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-49614-4.html
他会失败
执政党拥有军权是最正常的
台湾执政者也是明白之人
还是喜欢我们最伟大的领袖啊