自动化配置网络接口
根据如下要求配置;前提条件有创建完整的inventory主机清单。
-
统一接口名为team0。
-
team0-port1接口连接到eth1网络接口
-
team0-port2接口连接到eth2网络接口。
-
在servera上,接口将被静态分配IP地址为192.168.62.10/24和fc62:5265:6448:6174::a/64
-
在serverb上,接口将被静态分配IP地址为192.168.62.11/24和fc62:5265:6448:6174::b/64
运行playbook,仅为servera和serverb配置网络接口。在继续进行剩余的实验室要求之前,请确认playbook工作正常。
1.1 如果尚未安装,请在workstation上安装rhel-system-roles软件包。
[student@workstation cr-network]$ sudo yum -y install rhel-system-roles
1.2 编辑host_vars/servera.lab.example.com来定义servera的network_connections。它的值必须创建一 个名为team0的连接和一个名为team0的接口。它必须静态地为接口分配适当的IPv4和IPv6地址。
host_vars/servera.lab.example.com变量文件应包含以下内容:
---
network_connections:
# Create the team profile
- name: team0
state: up
type: team
interface_name: team0
ip:
dhcp4: no
auto6: no
address:
- 192.168.62.10/24
- fc62:5265:6448:6174::a/64
# Attach an ethernet port to the team
- name: team0-port1
state: up
type: ethernet
interface_name: eth1
master: team0
# Attach an ethernet port to the team
- name: team0-port2
state: up
type: ethernet
interface_name: eth2
master: team0
1.3 编辑host_vars/serverb.lab.example.com来定义servera的network_connections变量。它的值必须创 建一个名为team0连接和一个名为team0的接口。它必须静态地为接口分配适当的IPv4和IPv6地址。
host_vars/serverb.lab.example.com变量文件应包含以下内容:
---
network_connections:
# Create the team profile
- name: team0
state: up
type: team
interface_name: team0
ip:
dhcp4: no
auto6: no
address:
- 192.168.62.11/24
- fc62:5265:6448:6714::b/64
# Attach an ethernet port to the team
- name: team0-port1
state: up
type: ethernet
interface_name: eth1
master: team0
# Attach an ethernet port to the team
- name: team0-port2
state: up
type: ethernet
interface_name: eth2
master: team0
1.4 在config-network.yml中修改hosts指令。playbook在servera和serverb上运行。让它调用rhel-system-roles.network角色创建接口。
由此产生的config-network.yml应包含以下内容:
---
- name: Configure network interface
hosts:
- servera.lab.example.com
- serverb.lab.example.com
become: true
roles:
- rhel-system-roles.network
1.5 运行playbook为servera和serverb配置网络接口
[student@workstation cr-network]$ ansible-playbook config-network.yml
1.6 确认playbook是否有效并创建了接口。登录servera和serverb上,使用ping命令互相测试IPv4和IPv6的连通性。