ansible.cfg配置_如何在Ubuntu 18.04上安装和配置Ansible [快速入门]

ansible.cfg配置

介绍 (Introduction)

In this guide, we will discuss how to install and configure Ansible on an Ubuntu 18.04 server. For a more detailed version of this tutorial, with more explanations of each step, please refer to How to Install and Configure Ansible on Ubuntu 18.04.

在本指南中,我们将讨论如何在Ubuntu 18.04服务器上安装和配置Ansible。 有关本教程的更详细版本,以及每个步骤的更多说明,请参阅如何在Ubuntu 18.04上安装和配置Ansible

先决条件 (Prerequisites)

To follow this tutorial, you will need:

要遵循本教程,您将需要:

  • One Ansible Control Node: an Ubuntu 18.04 system where Ansible will be installed. This can be a remote server or a local machine.

    一个Ansible控制节点 :将安装Ansible的Ubuntu 18.04系统。 这可以是远程服务器或本地计算机。

  • One or more Ansible Hosts: one or more Ubuntu 18.04 servers that are accessible from your Control Node via SSH.

    一台或多台Ansible主机 :一台或多台Ubuntu 18.04服务器,可通过SSH从您的控制节点访问。

第1步-安装Ansible (Step 1 — Install Ansible)

From your control node, run the following command to include the official project’s PPA (personal package archive) in your system’s list of sources:

在控制节点上,运行以下命令以将官方项目的PPA(个人软件包存档)包括在系统的源列表中:

  • sudo apt-add-repository ppa:ansible/ansible

    sudo apt-add-repository ppa:可/可

Refresh your system’s package index with:

使用以下命令刷新系统的软件包索引:

  • sudo apt update

    sudo apt更新

Following this update, you can install the Ansible software with:

完成此更新后,您可以使用以下方法安装Ansible软件:

  • sudo apt install ansible

    sudo apt安装ansible

第2步-设置库存文件 (Step 2 — Set Up the Inventory File)

To edit the contents of your default Ansible inventory, open the /etc/ansible/hosts file using your text editor of choice:

要编辑默认Ansible清单的内容,请使用选择的文本编辑器打开/etc/ansible/hosts文件:

  • sudo nano /etc/ansible/hosts

    须藤nano / etc / ansible / hosts

The default inventory file provided by the Ansible installation contains a number of examples that you can use as references for setting up your inventory. The following example defines a group named [servers] with three different servers in it, each identified by a custom alias: server1, server2, and server3. Be sure to replace the highlighted IPs with the IP addresses of your Ansible hosts.

Ansible安装提供的默认清单文件包含许多示例,您可以将其用作设置清单的参考。 以下示例定义了一个名为[servers]的组,其中有三个不同的服务器,每个服务器都由一个自定义别名标识: server1server2server3 。 确保用Ansible主机的IP地址替换突出显示的IP。

/etc/ansible/hosts
/ etc / ansible / hosts
[servers]
server1 ansible_host=203.0.113.111
server2 ansible_host=203.0.113.112
server3 ansible_host=203.0.113.113

[all:vars]
ansible_python_interpreter=/usr/bin/python3

The all:vars subgroup sets the ansible_python_interpreter host parameter that will be valid for all hosts in this inventory. This parameter makes sure the remote server uses the /usr/bin/python3 Python 3 executable instead of /usr/bin/python (Python 2.7), which is not present on recent Ubuntu versions.

all:vars子组设置ansible_python_interpreter主机参数,该参数对该清单中的所有主机有效。 此参数可确保远程服务器使用/usr/bin/python3 Python 3可执行文件,而不是/usr/bin/python (Python 2.7),该文件在最新的Ubuntu版本中不存在。

Don’t forget to save and close the file when you’re finished.

完成后,别忘了保存并关闭文件。

步骤3 —测试连接 (Step 3 — Test Connection)

You can use the -u argument to specify the remote system user. When not provided, Ansible will try to connect as your current system user on the control node.

您可以使用-u参数指定远程系统用户。 如果未提供,Ansible将尝试以您当前的系统用户身份在控制节点上进行连接。

From your Ansible control node, run:

在您的Ansible控制节点上,运行:

  • ansible all -m ping -u root

    ansible all -m ping -u 根

You should get output similar to this:

您应该获得类似于以下的输出:


   
   
Output
server1 | SUCCESS => { "changed": false, "ping": "pong" } server2 | SUCCESS => { "changed": false, "ping": "pong" } server3 | SUCCESS => { "changed": false, "ping": "pong" }

If this is the first time you’re connecting to these servers via SSH, you’ll be asked to confirm the authenticity of the hosts you’re connecting to via Ansible. When prompted, type yes and then hit ENTER to confirm.

如果这是您第一次通过SSH连接到这些服务器,则会要求您确认通过Ansible连接的主机的真实性。 出现提示时,键入yes ,然后按ENTER进行确认。

Once you get a "pong" reply back from a host, it means you’re ready to run Ansible commands and playbooks on that server.

从主机收到"pong"回复后,这意味着您已准备好在该服务器上运行Ansible命令和剧本。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-18-04-quickstart

ansible.cfg配置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值