1.3. 准备控制节点
RHEL 在 AppStream
存储库中包括 Ansible Core
,其支持范围有限。如果您需要额外的 Ansible 支持,请联系红帽了解有关 Ansible Automation Platform
订阅的更多信息。
先决条件
- 在客户门户网站中注册该系统。
-
向系统附加了
Red Hat Enterprise Linux 服务器订阅
。 -
如果客户门户网站帐户中可用,您可以将
Ansible Automation Platform
订阅附加到该系统。
流程
安装
rhel-system-roles
软件包:[root@control-node]# dnf install rhel-system-roles
此命令将
Ansible Core
安装为依赖项。创建稍后用来管理和执行 playbook 的用户:
[root@control-node]# useradd ansible
切换到新创建的
ansible
用户:[root@control-node]# su - ansible
以这个用户身份执行其余步骤。
创建 SSH 公钥和私钥
[ansible@control-node]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/ansible/.ssh/id_rsa): password ...
为密钥文件使用推荐的默认位置。
- 可选:配置 SSH 代理,以防止 Ansible 每次建立连接时提示您输入 SSH 密钥密码。
使用以下内容创建
~/.ansible.cfg
文件:[defaults] inventory = /home/ansible/inventory remote_user = ansible [privilege_escalation] become = True become_method = sudo become_user = root become_ask_pass = True
使用这些设置:
- Ansible 管理指定清单文件中的主机。
-
当 Ansible 建立与受管节点的 SSH 连接时,Ansible 使用
remote_user
参数中设置的帐户。 Ansible 使用
sudo
实用程序以root
用户身份对受管节点执行任务。为安全起见,请在受管节点上配置
sudo
以要求输入远程用户的密码,成为root
用户。通过在~/.ansible.cfg
中指定become_ask_pass=True
设置,Ansible 在执行 playbook 时提示输入此密码。
~/.ansible.cfg
文件中的设置具有更高的优先级,并覆盖全局/etc/ansible/ansible.cfg
文件中的设置。创建
~/inventory
文件。例如,以下是 INI 格式的清单文件,它有三个主机,以及一个名为US
的主机组:managed-node-01.example.com [US] managed-node-02.example.com ansible_host=192.0.2.100 managed-node-03.example.com
请注意,控制节点必须能够解析主机名。如果 DNS 服务器无法解析某些主机名,请在主机条目旁边添加
ansible_host
参数来指定其 IP 地址。
验证