how to create bridge on main interface?


Hopefully this is good place to ask. If not, please suggest something

For quite some time I'm trying to figure out how to create a bridge
using main network interface (the only one which is routable to the host).

I have tried these Ansible tasks:

    - name: "Get {{ public_nic }} connection name"
      shell: nmcli --terse device | grep "^{{ public_nic }}:" | cut -d ':' -f 4
      register: public_connection_cmd
    - name: "Extract {{ public_nic }} connection name"
        public_connection: "{{ public_connection_cmd.stdout_lines|first|trim }}"

    - name: "Create brpublic bridge connection"
        conn_name: brpublic
        ifname: brpublic
        type: bridge
        stp: no
        state: present

    - name: "Put {{ public_nic }} device into brpublic"
        conn_name: brpublic-slave
        ifname: "{{ public_nic }}"
        type: bridge-slave
        master: brpublic
        state: present

    - name: "Remove old {{ public_nic }} connection"
        conn_name: "{{ public_connection }}"
        state: absent
      when: "public_connection != '' and public_connection != 'brpublic-slave'"

but this breaks the network on the last task.

I have also tried these two ways via "shell":

    set -xe

    old_connection=$( nmcli --terse device | grep "^{{ public_nic }}:" | cut -d ':' -f 4 )

    nmcli con add type bridge con-name brpublic ifname brpublic
    ###nmcli con add type bridge-slave con-name brpublic-slave ifname "{{ public_nic }}" master brpublic
    nmcli connection modify "$old_connection" master brpublic

    ###if [ -n "$old_connection" -a "$old_connection" != 'brpublic-slave' ]; then
    ###    nmcli c delete "$old_connection"

    nmcli con up brpublic

but this fails as well (script works, but at the end according to `ip a` IP
is still on the main interface, not on "brpublic").

Mine end goal is to have VM on that bridge that can be accessible from
outside network.

What is the right way to do that remotely?

Thank you in advance,

Jan Hutar   Performance Engineering
jhutar redhat com     Red Hat, Inc.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]