Ansible 简明教程
Ansible - Environment Setup
在本章中,我们将了解 Ansible 的环境设置。
In this chapter, we will learn about the environment setup of Ansible.
Installation Process
说到部署,主要有两种类型的机器:
Mainly, there are two types of machines when we talk about deployment −
-
Control machine − Machine from where we can manage other machines.
-
Remote machine − Machines which are handled/controlled by control machine.
一台控制机器可处理多台远程机器。因此,要管理远程机器,我们必须在控制机器上安装 Ansible。
There can be multiple remote machines which are handled by one control machine. So, for managing remote machines we have to install Ansible on control machine.
Control Machine Requirements
已安装 Python 2(版本 2.6 或 2.7)或 Python 3(版本 3.5 及更高版本)即可从任何机器上运行 Ansible。
Ansible can be run from any machine with Python 2 (versions 2.6 or 2.7) or Python 3 (versions 3.5 and higher) installed.
Note − Windows 不支持控制机器。
Note − Windows does not support control machine.
默认情况下,Ansible 使用 ssh 来管理远程机器。
By default, Ansible uses ssh to manage remote machine.
Ansible 不会添加任何数据库。它不需要任何守护进程来启动或使它持续运行。在管理远程机器时,Ansible does not 会在远程机器上安装或运行任何软件。因此,在迁移到新版本时无需考虑如何升级该软件。
Ansible does not add any database. It does not require any daemons to start or keep it running. While managing remote machines, Ansible does not leave any software installed or running on them. Hence, there is no question of how to upgrade it when moving to a new version.
可通过不同的方式在具有上述要求的控制机器上安装 Ansible。你可以通过 Apt、yum、pkg、pip、OpenCSW、pacman 等安装最新版本。
Ansible can be installed on control machine which have above mentioned requirements in different ways. You can install the latest release through Apt, yum, pkg, pip, OpenCSW, pacman, etc.
Installation through Apt on Ubuntu Machine
要安装 Ansible,需要在机器上配置 PPA。为此,需运行以下代码行:
For installing Ansible you have to configure PPA on your machine. For this, you have to run the following line of code −
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible $ sudo apt-get update
$ sudo apt-get install ansible
运行上述代码行后,即可通过 Ansible 管理远程机器。只需运行 Ansible–version 即可查看版本,并检查 Ansible 是否已正确安装。
After running the above line of code, you are ready to manage remote machines through Ansible. Just run Ansible–version to check the version and just to check whether Ansible was installed properly or not.