8.7. 使用 network RHEL 系统角色配置网络绑定
您可以使用 network
RHEL 系统角色远程配置网络绑定。
在 Ansible 控制节点上执行此步骤。
先决条件
- 您已准备好控制节点和受管节点。
- 以可在受管主机上运行 playbook 的用户登录到控制节点。
-
用于连接到受管节点的帐户对其具有
sudo
权限。 - 要在其上运行此 playbook 的受管节点或受管节点组列在 Ansible 清单文件中。
- 在服务器中安装两个或者两个以上物理或者虚拟网络设备。
流程
创建包含以下内容的 playbook 文件,如
~/bond-ethernet.yml
:--- - name: Configure the network hosts: managed-node-01.example.com tasks: - name: Configure a network bond that uses two Ethernet ports include_role: name: rhel-system-roles.network vars: network_connections: # Define the bond profile - name: bond0 type: bond interface_name: bond0 ip: address: - "192.0.2.1/24" - "2001:db8:1::1/64" gateway4: 192.0.2.254 gateway6: 2001:db8:1::fffe dns: - 192.0.2.200 - 2001:db8:1::ffbb dns_search: - example.com bond: mode: active-backup state: up # Add an Ethernet profile to the bond - name: bond0-port1 interface_name: enp7s0 type: ethernet controller: bond0 state: up # Add a second Ethernet profile to the bond - name: bond0-port2 interface_name: enp8s0 type: ethernet controller: bond0 state: up
这些设置使用以下设置定义网络绑定:
-
静态 IPv4 地址 -
192.0.2.1
和/24
子网掩码 -
静态 IPv6 地址 -
2001:db8:1::1
和/64
子网掩码 -
IPv4 默认网关 -
192.0.2.254
-
IPv6 默认网关 -
2001:db8:1::fffe
-
IPv4 DNS 服务器 -
192.0.2.200
-
IPv6 DNS 服务器 -
2001:db8:1::ffbb
-
DNS 搜索域 -
example.com
-
绑定的端口 -
enp7s0
和enp8s0
绑定模式 -
active-backup
注意在绑定上设置 IP 配置,而不是在 Linux 绑定的端口上设置。
-
静态 IPv4 地址 -
验证 playbook 语法:
# ansible-playbook ~/bond-ethernet.yml --syntax-check
请注意,这个命令只验证语法,不会防止错误但有效的配置。
运行 playbook:
# ansible-playbook ~/bond-ethernet.yml
其他资源
-
/usr/share/ansible/roles/rhel-system-roles.network/README.md
文件