Skip to content

Commit

Permalink
Add a network defined resource (#30)
Browse files Browse the repository at this point in the history
* add systemd::network defined resource

* manage systemd-networkd in init.pp
  • Loading branch information
bastelfreak authored and raphink committed Jul 13, 2017
1 parent 17e9594 commit 6e5db82
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,18 @@ Or provide the configuration file yourself. Systemd reloading and restarting of
source => "puppet:///modules/${module_name}/foo.conf",
}
```

### network

systemd-networkd is able to manage your network configuration. We provide a
defined resource which can write the interface configurations. systemd-networkd
needs to be restarted to apply the configs. The defined resource can do this
for you, besides managing the service itself.

```puppet
::systemd::network{'eth0.network':
source => "puppet:///modules/${module_name}/eth0.network",
manage_service => true,
restart_service => true,
}
```
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class systemd (
$service_limits = {},
Boolean $manage_resolved = true,
Boolean $manage_networkd = true,
){

Exec {
Expand Down Expand Up @@ -32,4 +33,11 @@
target => '/run/systemd/resolve/resolv.conf',
}
}

if $manage_networkd {
service{'systemd-networkd':
ensure => 'running',
enable => true,
}
}
}
30 changes: 30 additions & 0 deletions manifests/network.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -- Define: systemd::network
# Creates network config for systemd-networkd
define systemd::network (
Enum['file', 'absent'] $ensure = file,
Stdlib::Absolutepath $path = '/etc/systemd/network',
Optional[String] $content = undef,
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $target = undef,
Boolean $restart_service = true,
){

include ::systemd

if $restart_service {
$notify = Service['systemd-networkd']
} else {
$notify = undef
}

file { "${path}/${name}":
ensure => $ensure,
content => $content,
source => $source,
target => $target,
owner => 'root',
group => 'root',
mode => '0444',
notify => $notify,
}
}

2 comments on commit 6e5db82

@EmilienM
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bastelfreak FYI this patch broke our CI in OpenStack TripleO, see https://bugs.launchpad.net/tripleo/+bug/1704160

@bastelfreak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, already fixed in #32

Please sign in to comment.