Skip to content

Commit

Permalink
Add snippet defined resource
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Jul 19, 2021
1 parent 5aabfa9 commit dca90bb
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 25 deletions.
138 changes: 113 additions & 25 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@

* [`bird`](#bird): Install and configure bird

### Defined types

* [`bird::snippet`](#birdsnippet): manage a partial bird config file
on setups with many peers it's common to save each peer in a single file.
This is possible with this defined resource. Your bird config needs to contain an include statement!

## Classes

### `bird`
### <a name="bird"></a>`bird`

Install and configure bird

Expand All @@ -36,17 +42,40 @@ class { 'bird':

#### Parameters

The following parameters are available in the `bird` class.

##### `config_file_v4`
The following parameters are available in the `bird` class:

* [`config_file_v4`](#config_file_v4)
* [`config_template_v4`](#config_template_v4)
* [`daemon_name_v6`](#daemon_name_v6)
* [`package_name_v6`](#package_name_v6)
* [`daemon_name_v4`](#daemon_name_v4)
* [`package_name_v4`](#package_name_v4)
* [`config_path_v6`](#config_path_v6)
* [`config_path_v4`](#config_path_v4)
* [`enable_v6`](#enable_v6)
* [`manage_conf`](#manage_conf)
* [`manage_service`](#manage_service)
* [`service_v6_ensure`](#service_v6_ensure)
* [`service_v6_enable`](#service_v6_enable)
* [`service_v4_ensure`](#service_v4_ensure)
* [`service_v4_enable`](#service_v4_enable)
* [`config_file_v6`](#config_file_v6)
* [`config_template_v6`](#config_template_v6)
* [`manage_repo`](#manage_repo)
* [`config_content_v4`](#config_content_v4)
* [`config_content_v6`](#config_content_v6)
* [`v4_path`](#v4_path)
* [`v6_path`](#v6_path)

##### <a name="config_file_v4"></a>`config_file_v4`

Data type: `Optional[Stdlib::Filesource]`

Bird configuration file for IPv4.

Default value: ``undef``

##### `config_template_v4`
##### <a name="config_template_v4"></a>`config_template_v4`

Data type: `Optional[String[1]]`

Expand All @@ -55,111 +84,111 @@ will be passed into the template() function.

Default value: ``undef``

##### `daemon_name_v6`
##### <a name="daemon_name_v6"></a>`daemon_name_v6`

Data type: `String[1]`

The service name used by puppet resource

Default value: `'bird6'`

##### `package_name_v6`
##### <a name="package_name_v6"></a>`package_name_v6`

Data type: `String[1]`

The package name used by puppet resource

##### `daemon_name_v4`
##### <a name="daemon_name_v4"></a>`daemon_name_v4`

Data type: `String[1]`

The service name used by puppet resource

Default value: `'bird'`

##### `package_name_v4`
##### <a name="package_name_v4"></a>`package_name_v4`

Data type: `String[1]`

The package name used by puppet resource

Default value: `'bird'`

##### `config_path_v6`
##### <a name="config_path_v6"></a>`config_path_v6`

Data type: `Stdlib::Absolutepath`

The full path of the v6 configuration file

##### `config_path_v4`
##### <a name="config_path_v4"></a>`config_path_v4`

Data type: `Stdlib::Absolutepath`

The full path of the v4 configuration file

##### `enable_v6`
##### <a name="enable_v6"></a>`enable_v6`

Data type: `Boolean`

Boolean for enable IPv6 (install bird6 package). Defaults to false and it's only required if you use a legacy distribution that ships bird + bird6. Newer releases have native IPv6 support.

##### `manage_conf`
##### <a name="manage_conf"></a>`manage_conf`

Data type: `Boolean`

Boolean, global parameter to disable or enable mangagment of bird configuration files.

Default value: ``false``

##### `manage_service`
##### <a name="manage_service"></a>`manage_service`

Data type: `Boolean`

Boolean, global parameter to disable or enable mangagment of bird service.

Default value: ``false``

##### `service_v6_ensure`
##### <a name="service_v6_ensure"></a>`service_v6_ensure`

Data type: `Stdlib::Ensure::Service`

Bird IPv6 daemon ensure (shoud be running or stopped).

Default value: `'running'`

##### `service_v6_enable`
##### <a name="service_v6_enable"></a>`service_v6_enable`

Data type: `Boolean`

Boolean, enabled param of Bird IPv6 service (run at boot time).

Default value: ``false``

##### `service_v4_ensure`
##### <a name="service_v4_ensure"></a>`service_v4_ensure`

Data type: `Stdlib::Ensure::Service`

Bird IPv4 daemon ensure (shoud be running or stopped).

Default value: `'running'`

##### `service_v4_enable`
##### <a name="service_v4_enable"></a>`service_v4_enable`

Data type: `Boolean`

Boolean, enabled param of Bird IPv4 service (run at boot time).

Default value: ``false``

##### `config_file_v6`
##### <a name="config_file_v6"></a>`config_file_v6`

Data type: `Optional[Stdlib::Filesource]`

Bird configuration file for IPv6.

Default value: ``undef``

##### `config_template_v6`
##### <a name="config_template_v6"></a>`config_template_v6`

Data type: `Optional[String[1]]`

Expand All @@ -168,39 +197,98 @@ will be passed into the template() function.

Default value: ``undef``

##### `manage_repo`
##### <a name="manage_repo"></a>`manage_repo`

Data type: `Boolean`

Add the upstream repository from CZ.NIC. This is currently only supported for CentOS 7

Default value: ``false``

##### `config_content_v4`
##### <a name="config_content_v4"></a>`config_content_v4`

Data type: `Optional[String[1]]`

A string that will be used for the bird config file

Default value: ``undef``

##### `config_content_v6`
##### <a name="config_content_v6"></a>`config_content_v6`

Data type: `Optional[String[1]]`

A string that will be used for the bird6 config file

Default value: ``undef``

##### `v4_path`
##### <a name="v4_path"></a>`v4_path`

Data type: `Stdlib::Absolutepath`

Path to the bird binary

##### `v6_path`
##### <a name="v6_path"></a>`v6_path`

Data type: `Optional[Stdlib::Absolutepath]`

Optional path to the bird6 binary. Only set on legacy operating systems that run bird1

## Defined types

### <a name="birdsnippet"></a>`bird::snippet`

manage a partial bird config file
on setups with many peers it's common to save each peer in a single file.
This is possible with this defined resource. Your bird config needs to contain an include statement!

#### Examples

#####

```puppet
bird::snippet { 'AS4242420181':
content => "protocol bgp AS4242420181 from dnpeers {\n neighbor fe80::181:1%as20181 as 4242420181;\n}\n",
}
```

#### Parameters

The following parameters are available in the `bird::snippet` defined type:

* [`manage_v6`](#manage_v6)
* [`validate`](#validate)
* [`content`](#content)
* [`source`](#source)

##### <a name="manage_v6"></a>`manage_v6`

Data type: `Boolean`

for bird1, there is a dedicated instance for IPv6. if this boolean is true, the config will be used for that instance

Default value: ``false``

##### <a name="validate"></a>`validate`

Data type: `Boolean`

if the new file should be validated. Beware: For some statements it's not possible to modify and validate them, in those cases you need to disable the check

Default value: ``true``

##### <a name="content"></a>`content`

Data type: `Optional[String[1]]`

The content of the snippet. You cannot provide this in combination with $source.

Default value: ``undef``

##### <a name="source"></a>`source`

Data type: `Optional[Stdlib::Filesource]`

the source of the snippet. You cannot provide this in combination with $content.

Default value: ``undef``

22 changes: 22 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@
if $manage_service {
File[$config_path_v4] ~> Service[$daemon_name_v4]
}
# people might want to throw config snippets into the filesystem and include them in the main config
# we make this easier with the bird::snippet() defined resource. We create the directory for that here
$additional_config_path_v4 = "${dirname($config_path_v4)}/snippets"
unless defined(File[$additional_config_path_v4]) {
file { $additional_config_path_v4:
ensure => 'directory',
owner => 'root',
group => 'root',
require => Package[$package_name_v4];
}
}
}

if $enable_v6 {
Expand Down Expand Up @@ -206,6 +217,17 @@
if $manage_service {
File[$config_path_v6] ~> Service[$daemon_name_v6]
}
# people might want to throw config snippets into the filesystem and include them in the main config
# we make this easier with the bird::snippet() defined resource. We create the directory for that here
$additional_config_path_v6 = "${dirname($config_path_v6)}/snippets"
unless defined(File[$additional_config_path_v6]) {
file { $additional_config_path_v6:
ensure => 'directory',
owner => 'root',
group => 'root',
require => Package[$package_name_v6];
}
}
}
}
}
64 changes: 64 additions & 0 deletions manifests/snippet.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# @summary manage a partial bird config file
# on setups with many peers it's common to save each peer in a single file.
# This is possible with this defined resource. Your bird config needs to contain an include statement!
#
# @param manage_v6 for bird1, there is a dedicated instance for IPv6. if this boolean is true, the config will be used for that instance
# @param validate if the new file should be validated. Beware: For some statements it's not possible to modify and validate them, in those cases you need to disable the check
# @param content The content of the snippet. You cannot provide this in combination with $source.
# @param source the source of the snippet. You cannot provide this in combination with $content.
#
# @example
# bird::snippet { 'AS4242420181':
# content => "protocol bgp AS4242420181 from dnpeers {\n neighbor fe80::181:1%as20181 as 4242420181;\n}\n",
# }
#
# @author Tim Meusel <tim@bastelfreak.de>
#
define bird::snippet (
Boolean $manage_v6 = false,
Boolean $validate = true,
Optional[String[1]] $content = undef,
Optional[Stdlib::Filesource] $source = undef,
) {
include bird
if $content == NotUndef and $source == NotUndef {
fail('you can only set $content or $source')
}
if $content == Undef and $source == Undef {
fail('you need to set $content or $source')
}
if $manage_v6 {
$additional_config_path = $bird::additional_config_path_v6
$validate_cmd = "${bird::v6_path} -p -c ${bird::config_path_v6}"
$require = File[$bird::config_path_v6]
$daemon_name = Service[$bird::daemon_name_v6]
} else {
$additional_config_path = $bird::additional_config_path_v4
$validate_cmd = "${bird::v4_path} -p -c ${bird::config_path_v4}"
$require = File[$bird::config_path_v4]
$daemon_name = Service[$bird::daemon_name_v4]
}
$filepath = "${additional_config_path}/${title}"
# we cannot validate the snippets, only the whole config
# the main config file includes the snippets, hence we validate the main config for each snippet
# because of that, the snippets require the main file
if $validate {
$_validate_cmd = $validate_cmd
} else {
$_validate_cmd = undef
}
file { $filepath:
ensure => 'file',
source => $source,
content => $content,
owner => 'root',
group => 'root',
mode => '0644',
validate_cmd => $_validate_cmd,
require => $require,
}
if $bird::manage_service {
File[$filepath] ~> $daemon_name
}
}

0 comments on commit dca90bb

Please sign in to comment.