Skip to content

Commit

Permalink
playbooks/cluster_setup_network: configure PTP
Browse files Browse the repository at this point in the history
If a PTP VLAN is defined configure and enable the PTP.

Signed-off-by: Mathieu Dupré <[email protected]>
  • Loading branch information
dupremathieu authored and insatomcat committed Nov 28, 2022
1 parent f88f365 commit 8e2e95d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 16 deletions.
15 changes: 15 additions & 0 deletions inventories/seapath.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ all:
cluster_interface: TODO
# Set the cluster IP address
cluster_ip_addr: TODO
# Optional PTP VLAN IP address
ptp_vlan_address: TODO
# The interface used for PTP
ptp_vlan_interface: TODO
# Optional additional network configuration list.
# For more information see roles/systemd_networkd/README.md
custom_network:
Expand Down Expand Up @@ -94,6 +98,10 @@ all:
cluster_interface: TODO
# Set the cluster IP address
cluster_ip_addr: TODO
# Optional PTP VLAN IP address
ptp_vlan_address: TODO
# The interface use for PTP
ptp_vlan_interface: TODO
# Optional additional Network configuration list
# For more information see roles/systemd_networkd/README.md
custom_network:
Expand Down Expand Up @@ -152,11 +160,15 @@ all:
ansible_host: TODO
# Set the public interface
network_interface: TODO
# The interface used for PTP
ptp_vlan_interface: TODO
ip_addr: "{{ ansible_host }}"
# Set the cluster interface
cluster_interface: TODO
# Set the cluster IP address
cluster_ip_addr: TODO
# Optional PTP VLAN IP address
ptp_vlan_address: TODO
custom_network:
10-cluster:
- Match:
Expand Down Expand Up @@ -245,6 +257,9 @@ all:
# The VM DHCP server IP address assigned to the "dhcp_bind_interface"
# interface
dhcp_vm_bind_interface: TODO
# Optional VLAN tag id to create a PTP VLAN
ptp_vlan: TODO
ptp_vlan_interface: "{{ network_interface }}"
# Path where the CI must search the images
# e.g. /var/jenkins_home/images
image_directory: TODO
62 changes: 53 additions & 9 deletions playbooks/cluster_setup_network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,60 @@
- ../vars/network_vars.yml
roles:
- systemd_networkd
vars:
apply_config: "{{ apply_network_config | default(false) }}"
tasks:
- block:
- name: add ptp vlan interfaces
template:
src: "../templates/{{ item }}.j2"
dest: "/etc/systemd/network/{{ item }}"
group: systemd-network
with_items:
- 00-ptp.netdev
- 01-ptp.network
register: ptp_interface
- name: Register reboot
set_fact:
need_reboot: true
when:
- not apply_config
- ptp_interface.changed
when:
- ptp_vlan_interface is defined
- ptp_vlan is defined
- ptp_vlan_address is defined
- name: Restart systemd-networkd
ansible.builtin.systemd:
name: systemd-networkd
state: restarted
when:
apply_config


- name: Network configuration
- name: Configure PTP ansible.builtin.service
hosts: cluster_machines
vars:
apply_config: "{{ apply_network_config | default(false) }}"
tasks:
- name: Restart systemd-networkd
ansible.builtin.systemd:
name: systemd-networkd
state: restarted
- block:
- name: disable systemd-timesyncd service
ansible.builtin.systemd:
name: systemd-timesyncd.service
enabled: no
state: stopped
- name: Enable ptp service
ansible.builtin.systemd:
name: [email protected]
enabled: yes
- name: Start ptp service
ansible.builtin.systemd:
name: [email protected]
state: started
when: apply_config or (need_reboot is defined and not need_reboot)
when:
apply_config
- ptp_vlan_interface is defined
- ptp_vlan is defined

- name: Configure hosts and hostname
hosts: cluster_machines
Expand Down Expand Up @@ -107,14 +149,17 @@
line: 'NTP={{ ntp_servers }}'
- regexp: '^\s*#?\s*(FallbackNTP=).*$'
line: 'FallbackNTP={{ fallback_ntp_servers | default("") }}'
when:
- ptp_vlan_interface is not defined
- ptp_vlan is not defined
notify:
- Restart systemd timesyncd

handlers:
- name: Restart systemd timesyncd
ansible.builtin.service:
name: systemd-timesyncd
state: restarted

- name: Configure syslog-ng
hosts: cluster_machines
tasks:
Expand All @@ -127,7 +172,6 @@
state: present
notify:
- Restart systemd syslog-ng

handlers:
- name: Restart systemd syslog-ng
vars:
Expand All @@ -136,7 +180,7 @@
name: syslog-ng@default
state: restarted
when:
apply_config
apply_config or (need_reboot is defined and not need_reboot)

- name: Configure systemd-networkd-wait-online.service
hosts: hypervisors
Expand Down
8 changes: 8 additions & 0 deletions templates/00-ptp.netdev.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

[NetDev]
Name=ptp
Kind=vlan

[VLAN]
Id={{ ptp_vlan }}
7 changes: 7 additions & 0 deletions templates/01-ptp.network.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

[Match]
Name=ptp

[Network]
Address={{ ptp_vlan_address }}/{{ ptp_vlan_mask | default('24') }}
19 changes: 12 additions & 7 deletions vars/network_vars.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Copyright (C) 2021, RTE (http://www.rte-france.com)
# SPDX-License-Identifier: Apache-2.0
---
systemd_networkd_network_custom: "{{ custom_network |default([]) }}"
_systemd_networkd_network_custom: ["{{ custom_network |default([]) }}"]

wired_systemd_networkd_network:
_vlan_conditionnal: "{% if ptp_vlan is defined %}[{'VLAN': 'ptp'}]{% else %}[]{% endif %}"

_network_common:
- Gateway: "{{ gateway_addr }}"
- Address: "{{ ip_addr }}/{{ subnet | default(24) }}"
- DNS: "{{ dns_server }}"

_wired_systemd_networkd_network:
00-wired:
- Match:
- Name: "{{ network_interface }}"
- Network:
- Gateway: "{{ gateway_addr }}"
- Address: "{{ ip_addr }}/{{ subnet | default(24) }}"
- DNS: "{{ dns_server }}"
- Network: "{{ _network_common + _vlan_conditionnal }}"


systemd_networkd_network: "{{ wired_systemd_networkd_network | combine(systemd_networkd_network_custom) }}"
systemd_networkd_network: "{{ _wired_systemd_networkd_network | combine(_systemd_networkd_network_custom) }}"

0 comments on commit 8e2e95d

Please sign in to comment.