network_systemdnetworkd, network_netplan: auto-create PTP VLAN interface#918
network_systemdnetworkd, network_netplan: auto-create PTP VLAN interface#918dupremathieu wants to merge 3 commits into
Conversation
When both ptp_interface and ptp_vlanid are defined and non-empty, the network roles now automatically create the VLAN interface needed by the timemaster role. - network_systemdnetworkd: generate .netdev and .network profiles for the PTP VLAN interface (e.g. eno1.100). - network_netplan: generate a supplemental /etc/netplan/99-ptp-vlan.yaml. - Document the new ptp_interface and ptp_vlanid variables in both roles' README.md. If ptp_vlanid or ptp_interface is undefined, none, or empty, nothing is created (backward compatible). Signed-off-by: Mathieu Dupré <mathieu.dupre@savoirfairelinux.com>
Add Molecule tests for the network_systemdnetworkd Ansible role using the Podman driver and the geerlingguy/docker-debian13-ansible image. Test scenarios covered: - .link profile generation (10-eth0.link with Match and Link sections) - .netdev profile generation (20-bridge0.netdev with NetDev section) - .network profile generation (30-test0.network with Match and Network sections) - File ownership (root:systemd-network) and permissions (0640) - systemd-networkd service enablement The tests exercise the network_simple=true code path and disable systemd-resolved to avoid container-specific issues. Also add the missing "namespace: seapath" to meta/main.yml to satisfy Molecule/Galaxy FQCN requirements. Signed-off-by: Mathieu Dupré <mathieu.dupre@savoirfairelinux.com>
Keep the original default molecule scenario with network_simple: true. Add a new 'ptp_vlan' molecule scenario that tests the network_defaults.yml code path with ptp_interface and ptp_vlanid defined, verifying the auto-generated PTP VLAN files: - 80-ptp-vlan.netdev - 80-ptp-parent.network - 80-ptp-vlan.network Signed-off-by: Mathieu Dupré <mathieu.dupre@savoirfairelinux.com>
5ffd251 to
98a5aae
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds automatic creation of a PTP VLAN interface (e.g., eno1.100) when ptp_interface and ptp_vlanid are set, so the timemaster role can rely on the VLAN interface existing. It updates both the systemd-networkd and netplan network roles and documents the new variables.
Changes:
network_systemdnetworkd: generates.netdev+.networkprofiles for the PTP VLAN interface and parent attachment.network_netplan: generates a supplemental/etc/netplan/99-ptp-vlan.yamlwhen PTP VLAN vars are set.- Adds Molecule scenarios and updates READMEs / role metadata.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| roles/network_systemdnetworkd/vars/network_defaults.yml | Adds conditional PTP VLAN netdev/network definitions and merges them into generated config. |
| roles/network_systemdnetworkd/molecule/ptp_vlan/verify.yml | Adds Molecule verification for PTP VLAN systemd-networkd profiles. |
| roles/network_systemdnetworkd/molecule/ptp_vlan/molecule.yml | Adds Molecule scenario wiring for PTP VLAN variables. |
| roles/network_systemdnetworkd/molecule/default/verify.yml | Adds baseline Molecule verification for systemd-networkd outputs. |
| roles/network_systemdnetworkd/molecule/default/prepare.yml | Prepares Debian container environment for systemd-networkd Molecule tests. |
| roles/network_systemdnetworkd/molecule/default/molecule.yml | Adds default Molecule scenario definition. |
| roles/network_systemdnetworkd/molecule/default/converge.yml | Converges the systemd-networkd role in Molecule. |
| roles/network_systemdnetworkd/meta/main.yml | Adds Ansible Galaxy namespace. |
| roles/network_systemdnetworkd/README.md | Documents ptp_interface and ptp_vlanid. |
| roles/network_netplan/templates/ptp_vlan.yaml.j2 | Adds netplan snippet template for PTP VLAN interface. |
| roles/network_netplan/tasks/main.yml | Adds task to render the supplemental netplan PTP VLAN file. |
| roles/network_netplan/README.md | Documents ptp_interface and ptp_vlanid behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| network_systemdnetworkd_ptp_vlan_network: | ||
| 80-ptp-parent: | ||
| - Match: | ||
| - Name: "{{ ptp_interface | default('') }}" | ||
| - Network: | ||
| - VLAN: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" |
There was a problem hiding this comment.
The .network file 80-ptp-parent matches ptp_interface and sets VLAN=..., but systemd-networkd selects only the first matching .network file by lexical order. If ptp_interface is also matched by an earlier profile (e.g., the role’s existing 79-wired when ptp_interface == network_interface, or any user custom_network with a lower prefix), 80-ptp-parent will be ignored and the VLAN device will never be attached to the parent link. Consider injecting the VLAN= entry into the actual .network profile that matches the parent interface, or otherwise ensuring the VLAN attachment happens in the effective profile.
| - name: Generate PTP VLAN netplan configuration | ||
| when: | ||
| - ptp_interface is defined | ||
| - ptp_interface is not none | ||
| - ptp_interface | length > 0 |
There was a problem hiding this comment.
Generate PTP VLAN netplan configuration is inside a block guarded by when: netplan_configurations is defined. With the current structure, setting ptp_interface/ptp_vlanid will not create /etc/netplan/99-ptp-vlan.yaml unless netplan_configurations is also defined, which contradicts the documented/PR behavior. Consider moving the PTP VLAN templating (and ensuring /etc/netplan exists) outside that conditional, or broadening the block condition to include the PTP VLAN variables.
| and ptp_vlanid is defined and ptp_vlanid is not none and ptp_vlanid | string | length > 0 }} | ||
|
|
||
| network_systemdnetworkd_ptp_vlan_netdev: | ||
| 80-ptp-vlan: | ||
| - NetDev: | ||
| - Name: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" | ||
| - Kind: "vlan" | ||
| - VLAN: | ||
| - Id: "{{ ptp_vlanid | default('') }}" | ||
|
|
||
| network_systemdnetworkd_ptp_vlan_network: | ||
| 80-ptp-parent: | ||
| - Match: | ||
| - Name: "{{ ptp_interface | default('') }}" | ||
| - Network: | ||
| - VLAN: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" | ||
| 80-ptp-vlan: | ||
| - Match: | ||
| - Name: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" |
There was a problem hiding this comment.
network_systemdnetworkd_ptp_vlan_enabled only checks that ptp_vlanid is non-empty, but VLAN IDs outside 1-4094 (e.g., 0 or 4095+) will still generate invalid systemd-networkd config. It would be safer to cast ptp_vlanid to int and validate the allowed range (or fail fast with a clear assertion) before generating the .netdev/.network profiles.
| and ptp_vlanid is defined and ptp_vlanid is not none and ptp_vlanid | string | length > 0 }} | |
| network_systemdnetworkd_ptp_vlan_netdev: | |
| 80-ptp-vlan: | |
| - NetDev: | |
| - Name: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" | |
| - Kind: "vlan" | |
| - VLAN: | |
| - Id: "{{ ptp_vlanid | default('') }}" | |
| network_systemdnetworkd_ptp_vlan_network: | |
| 80-ptp-parent: | |
| - Match: | |
| - Name: "{{ ptp_interface | default('') }}" | |
| - Network: | |
| - VLAN: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" | |
| 80-ptp-vlan: | |
| - Match: | |
| - Name: "{{ (ptp_interface | default('')) + '.' + (ptp_vlanid | default('') | string) }}" | |
| and ptp_vlanid is defined and ptp_vlanid is not none and ptp_vlanid | string | length > 0 | |
| and (ptp_vlanid | int) >= 1 and (ptp_vlanid | int) <= 4094 }} | |
| network_systemdnetworkd_ptp_vlan_netdev: | |
| 80-ptp-vlan: | |
| - NetDev: | |
| - Name: "{{ (ptp_interface | default('')) + '.' + ((ptp_vlanid | int) | string) }}" | |
| - Kind: "vlan" | |
| - VLAN: | |
| - Id: "{{ ptp_vlanid | int }}" | |
| network_systemdnetworkd_ptp_vlan_network: | |
| 80-ptp-parent: | |
| - Match: | |
| - Name: "{{ ptp_interface | default('') }}" | |
| - Network: | |
| - VLAN: "{{ (ptp_interface | default('')) + '.' + ((ptp_vlanid | int) | string) }}" | |
| 80-ptp-vlan: | |
| - Match: | |
| - Name: "{{ (ptp_interface | default('')) + '.' + ((ptp_vlanid | int) | string) }}" |
When both ptp_interface and ptp_vlanid are defined and non-empty, the network roles now automatically create the VLAN interface needed by the timemaster role.
If ptp_vlanid or ptp_interface is undefined, none, or empty, nothing is created (backward compatible).