Giter VIP home page Giter VIP logo

Comments (7)

tabowling avatar tabowling commented on August 22, 2024

Here is an example playbook.

---
- hosts: all
  become: yes
  become_method: sudo
  become_user: root
  vars:
    network_connections:

      - name: net0  # Can we rename the primary interface?!?!?!
        state: present
        type: ethernet
#        interface_name: eth0
        mac: "{{ hostvars[inventory_hostname].net0_mac }}"
        autoconnect: yes
        ip:
          dhcp4: yes
          auto6: no

      - mac: "{{ hostvars[inventory_hostname].net0_mac }}"
        state: absent
        # need to ensure this interface is completely unused 
        # before reusing it for something else.
  roles:
    - role: rhel-system-roles.network
#    - role: linux-system-roles.network

from network.

tabowling avatar tabowling commented on August 22, 2024

Ansible facts provides all details of all net configurations accessible via variables at runtime. Here is an example playbook that accesses them and outputs them to the console.

---

- hosts: all
  become: yes
  become_method: sudo
  become_user: root

  tasks:
    - name: find interface facts
      debug:
        msg: "{{ hostvars[inventory_hostname]['ansible_%s' | format(item)] }}"
      with_items: "{{ ansible_interfaces }}"

Here are some other helpful commands

ansible rhel74-test -m setup -a 'gather_subset=network'
ansible rhel74-test -m setup -a 'gather_subset=network filter=ansible_interfaces'
ansible rhel74-test -m setup -a 'gather_subset=network' |grep -e ansible_e -e macaddr -e hostname -e device

from network.

tabowling avatar tabowling commented on August 22, 2024

Here is an example of how I am managing the inventory locally in my /etc/ansible/hosts file. This could be similar to how Ansible Tower or Satellite might keep an inventory of the nodes they manage.

This is how I was passing the MAC in as a variable in the first playbook example I submitted.

all:
  hosts:
    util6vm:
      net0_mac: "52:54:00:64:c0:fd"
      net1_mac: "52:54:00:23:b2:28"
      net2_mac: "52:54:00:5e:bc:e9"
      net3_mac: "52:54:00:46:55:59"
      net4_mac: "52:54:00:b5:4c:8f"
      net5_mac: "52:54:00:97:7c:96"
      webbond_ip: '192.168.75.231/24'
      webbond-link1: net2_mac
      webbond-link2: net4_mac
      dbbond_ip: '192.168.75.241/24'
      dbbond-link1: net3_mac
      dbbond-link2: net5_mac
    util7vm:
      net0_mac: "52:54:00:92:34:c8"
      net1_mac: "52:54:00:92:37:36"
      net2_mac: "52:54:00:61:bf:85"
      net3_mac: "52:54:00:3f:a4:d8"
      net4_mac: "52:54:00:d9:8c:d7"
      net5_mac: "52:54:00:a0:6e:f2"
      webbond_ip: '192.168.75.232/24'
      webbond-link1: net2_mac
      webbond-link2: net4_mac
      dbbond_ip: '192.168.75.242/24' 
      dbbond-link1: net3_mac
      dbbond-link2: net5_mac

from network.

thom311 avatar thom311 commented on August 22, 2024

Need the ability to [down/up, delete/rename conn name, modify attributes] of any NICs based on MAC or pci addr

Regarding "delete/rename conn name": the "name" is the identifier of a profile. Requesting to "rename" the identifier, essentially means to delete the old profile and create another profile with a different name. Requesting to "delete" an identifier, essentially means to delete the profile. Both is possible today.
There is no "conn name" without a profile, and there is no profile without a name.
I am not sure why there is the state:present example in comment #44 (comment) . You can already write a profile that matches on a device by MAC address and not by interface name.

   - name: net0 # logical-name, e.g. dmz1, prod, net0
     mac: "{{ hostvars[inventory_hostname].net0_mac }}"

Maybe that is the source of the misunderstanding: the name in the role is not the name of the networking device. You may call it net0 if that is suitable, or of course also eth0 to indicate that this profile is intended for the interface "eth0". But the name of the profile must not at all correspond to the name of the interface. If you don't know the (unpredictable) interface name, then the profile's name should be different than the interface name.

Regarding "Need the ability to [down/up, [...] modify attributes] of any NICs based [...]": the role operates in terms of providers (NetworkManager/initscripts). Both of these providers offer no useful API that works without profiles. How would the role set the NIC up, without creating a profile (that is, without calling ifup net0)? This essentially requests to implement something like initscripts inside the role itself. Should it persist this configuration? How? As ifcfg-files? Why would it then not use ifup/ifdown which is an existing API (albeit limited).

from network.

tyll avatar tyll commented on August 22, 2024

IMHO there are too many issues here for one ticket and the examples are too complicated. Are we discussing the name: net0 configuration or the mac: ... state: absent configuration? For the latter I was considering to add a switch to make the role remove all network profiles from the system that it does not know about to make sure that the configuration matches the playbook. Also what do you expect to happen for mac: ... state: absent?

  1. The role should remove all connection profiles that contain this mac address
  2. The role should remove all connection profiles that configure directly an interface (DEVICE= in ifcfg files) that currently uses this mac address
  3. If it does 1) or 2) for a bonding slave, it should also remove the bonding master
    1. but only when all slaves are removed

IMHO to best discuss the behavior we need bug reports that

  1. Describe the complete relevant configuration of a host (e.g. all initscripts config or all NM config + info about the current network state)
  2. Show an playbook that should be applied to this host
  3. Show the resulting behavior/network state
  4. Describe how this behavior/state does not match the expectation

in case there is a bug. If there is a missing feature, we probably need 1. + the wished behavior/resulting state.

from network.

tabowling avatar tabowling commented on August 22, 2024

I've separated out the request for deleting all profiles of a given interface to #92

from network.

tyll avatar tyll commented on August 22, 2024

It is now possible to define profiles that match by PCI address, mac address or name and to remove all profiles that are not specified. IMHO this seems to be enough possibilities at this time, therefore I close this.

from network.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.