Comments (7)
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.
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.
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.
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.
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
?
- The role should remove all connection profiles that contain this mac address
- The role should remove all connection profiles that configure directly an interface (
DEVICE=
in ifcfg files) that currently uses this mac address - If it does 1) or 2) for a bonding slave, it should also remove the bonding master
-
- but only when all slaves are removed
IMHO to best discuss the behavior we need bug reports that
- Describe the complete relevant configuration of a host (e.g. all initscripts config or all NM config + info about the current network state)
- Show an playbook that should be applied to this host
- Show the resulting behavior/network state
- 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.
I've separated out the request for deleting all profiles of a given interface to #92
from network.
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)
- Feature request: support adding tun devices HOT 14
- Routing rules improvement HOT 6
- Eliminate non-inclusive language HOT 5
- Address CodeQL warnings HOT 4
- Network override HOT 1
- add 'auto-dns' option also to network_connections HOT 6
- How to keep existing profile name HOT 3
- Verify and document no-aaaa DNS option HOT 2
- network_state should not change IPv6 state when not configured HOT 2
- Question Changing the IP of the remote host HOT 3
- ipv4.dns-data: unknown property (7) HOT 6
- RFE: Add support for DNS caching HOT 3
- WireGuard support HOT 1
- Rename the task `name: Check if rpm ostree system - cannot test` into a meaningful name explaining the reason for skipping test HOT 2
- Add support for veth pair HOT 3
- Add support for scope and src route options HOT 4
- not idempotent HOT 4
- Need further output from "check" mode HOT 7
- VRF Support HOT 2
- EL-7 tests fails because there is no EPEL-7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from network.