【问题标题】:How to create an openvswitch bridge using main network interface with Ansible?如何使用 Ansible 的主网络接口创建 openvswitch 网桥?
【发布时间】:2018-03-28 10:36:04
【问题描述】:

主要是我正在尝试构建一个 ansible 角色/剧本,它将配置一个使用机器的主/主要网络接口的 openvswitch 网桥,并避免大多数 common problem with openvswitch bridges - 在添加端口时被锁定。

$ ip addr flush dev eth0
$ ip addr add 192.168.128.5/24 dev br0
$ ip link set br0 up

正如您自己了解的那样,在使用 ansible (ssh) 进行配置时,很容易失去对目标机器的访问权限。

为简化问题,假设我们已经知道主网络接口 (eth0) 的名称,并且它是使用 DHCP 配置的。

【问题讨论】:

    标签: ansible openvswitch bridging


    【解决方案1】:

    一种解决方案是通过 ansible 在您的从机上加载脚本。创建脚本:

    脚本.sh

    #!/bin/bash
    sudo ip addr flush dev eth0
    sudo ip addr add 192.168.128.5/24 dev br0
    sudo ip link set br0 up
    

    然后是一本剧本,它将发送脚本并执行它。 像这样:

    - hosts: slave
      tasks:
      - name: copy script
        copy: src=./script.sh dest=/root/script.sh mode=a+x
      - name: execute script
        shell: ./root/script.sh >> somelog.txt
    

    编辑:

    >     - hosts: slave
    >       tasks:
    >       - name: copy/execute script
    >         copy: src=./script.sh dest=/root/script.sh mode=a+x
    >         shell: ./root/script.sh >> somelog.txt
    >         async: 10
    

    【讨论】:

    • 使用单个 script 任务而不是 copy/shell 对并添加 async 以使其对可能的连接中断更加健壮。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-25
    • 2020-07-14
    相关资源
    最近更新 更多