自动化配置网络接口

自动化配置网络接口

根据如下要求配置;前提条件有创建完整的inventory主机清单。

  • 统一接口名为team0

  • team0-port1接口连接到eth1网络接口

  • team0-port2接口连接到eth2网络接口。

  • servera上,接口将被静态分配IP地址为192.168.62.10/24fc62:5265:6448:6174::a/64

  • serverb上,接口将被静态分配IP地址为192.168.62.11/24fc62:5265:6448:6174::b/64

运行playbook,仅为serveraserverb配置网络接口。在继续进行剩余的实验室要求之前,请确认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来定义serveranetwork_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来定义serveranetwork_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在serveraserverb上运行。让它调用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为serveraserverb配置网络接口

[student@workstation cr-network]$ ansible-playbook config-network.yml

1.6 确认playbook是否有效并创建了接口。登录serveraserverb上,使用ping命令互相测试IPv4和IPv6的连通性。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值