Skip to content

Commit

Permalink
Merge pull request #68 from toanju/networkd-reload
Browse files Browse the repository at this point in the history
networkd reload
  • Loading branch information
myii authored Apr 26, 2021
2 parents d77297e + 34dd64b commit c575a25
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
11 changes: 8 additions & 3 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ systemd:

## networkd
networkd:
fileattr:
br0.network:
user: systemd-network
group: systemd-network
mode: "0600"
profiles:
network:
# eth0.network
eth0:
# br0.network
br0:
- Match:
- Name: eth0
- Name: br0
- Network:
- DHCP: "yes"

Expand Down
3 changes: 3 additions & 0 deletions systemd/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ systemd:
PollIntervalMaxSec: 2048

networkd:
# networkctl reload is available since systemd 244
networkctl_reload: false
pkg: {}
fileattr: {}
path: /etc/systemd/network
service: systemd-networkd
wait_online: true
Expand Down
42 changes: 29 additions & 13 deletions systemd/networkd/profiles.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,42 @@
{%- set networkd = systemd.get('networkd', {}) %}
{%- set profiles = networkd.get('profiles', {}) %}
{%- if networkd.networkctl_reload %}
include:
- systemd.reload
- systemd.networkd.reload
{%- endif %}
{% if profiles is mapping %}
{% for networkdprofile, types in profiles.items() %}
{% for profile, profileconfig in types.items() %}
{%- if profiles is mapping %}
/etc/systemd/network/{{ profile }}.{{ networkdprofile }}:
file.managed:
- template: jinja
- source: salt://systemd/networkd/templates/profile.jinja
/etc/systemd/network:
file.directory:
- user: root
- group: root
- mode: '0644'
- makedirs: true
- dir_mode: 755
{%- for networkdprofile, types in profiles.items() %}
{%- for profile, profileconfig in types.items() %}
{%- set filename = profile ~ "." ~ networkdprofile %}
{%- set user = networkd.fileattr.get(filename, {}).user | default("root") %}
{%- set group = networkd.fileattr.get(filename, {}).group | default("root") %}
{%- set mode = networkd.fileattr.get(filename, {}).mode | default("0644") %}
/etc/systemd/network/{{ filename }}:
file.managed:
- template: jinja
- source: salt://systemd/networkd/templates/profile.jinja
- user: {{ user }}
- group: {{ group }}
- mode: {{ mode }}
- context:
config: {{ profileconfig|json }}
- require:
- file: /etc/systemd/network
{%- if networkd.networkctl_reload %}
- watch_in:
- cmd: reload_systemd_configuration
{% endfor %}
{% endfor %}
{% endif %}
- cmd: systemd-networkd-reload-cmd-wait
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- endif %}
9 changes: 9 additions & 0 deletions systemd/networkd/reload.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include:
- systemd.networkd

systemd-networkd-reload-cmd-wait:
cmd.wait:
- name: networkctl reload
- runas: root
- require:
- service: networkd
2 changes: 1 addition & 1 deletion systemd/networkd/templates/profile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{%- endfor -%}
{%- endif -%}
{%- endfor %}
{% endfor %}
{%- endfor %}
{%- endmacro -%}

# This file is managed by Salt via {{ source }}
Expand Down
1 change: 1 addition & 0 deletions systemd/osmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Fedora:
pkgs_extra:
- python3-systemd
networkd:
networkctl_reload: true
pkg: {}
resolved:
pkg: {}
8 changes: 4 additions & 4 deletions test/integration/default/controls/networkd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
it { should_not exist }
end

describe file('/etc/systemd/network/eth0.network') do
describe file('/etc/systemd/network/br0.network') do
its('type') { should eq :file }
its('mode') { should cmp '0644' }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
its('mode') { should cmp '0600' }
its('owner') { should eq 'systemd-network' }
its('group') { should eq 'systemd-network' }
end

describe file('/etc/systemd/network/br0.netdev') do
Expand Down

0 comments on commit c575a25

Please sign in to comment.