Defined Type: podman::network

Defined in:
manifests/network.pp

Summary

Create a podman network with defined flags

Overview

Examples:

podman::network { 'mnetwork':
  driver   => 'bridge',
  internal => true,
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    State of the resource must be either ‘present’ or ‘absent’.

  • disable_dns (Boolean) (defaults to: false)

    Disables the DNS plugin for this network which if enabled, can perform container to container name resolution.

  • driver (Enum['bridge', 'macvlan']) (defaults to: 'bridge')

    Driver to manage the network.

  • opts (Array[String]) (defaults to: [])

    A list of driver specific options.

  • gateway (Optional[String]) (defaults to: undef)

    Define the gateway for the network. Must also provide the subnet.

  • internal (Boolean) (defaults to: false)

    Restrict external access of this network.

  • ip_range (Optional[String]) (defaults to: undef)

    Allocate container IP from a range. The range must be a complete subnet and in CIDR notation.

  • labels (Hash[String,String]) (defaults to: {})

    A hash of metadata labels to set on the network.

  • subnet (Optional[String]) (defaults to: undef)

    The subnet in CIDR notation

  • ipv6 (Boolean) (defaults to: false)

    Enable IPv6 (dual-stack) networking.

  • user (String) (defaults to: '')

    Optional user for creating rootless container networks. For rootless containers, the user must also be defined as a puppet resource that includes at least ‘uid’, ‘gid’, and ‘home’ attributes.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'manifests/network.pp', line 46

define podman::network (
  Enum['present', 'absent'] $ensure = 'present',
  Enum['bridge', 'macvlan'] $driver = 'bridge',
  Boolean $disable_dns = false,
  Array[String] $opts = [],
  Optional[String] $gateway = undef,
  Boolean $internal = false,
  Optional[String] $ip_range = undef,
  Hash[String,String] $labels = {},
  Optional[String] $subnet = undef,
  Boolean $ipv6 = false,
  String $user           = '',
) {
  require podman::install

  $_disable_dns = $disable_dns ? {
    true    => '--disable-dns',
    default => '',
  }

  # Convert opts list to command arguments
  $_opts = $opts.reduce('') |$mem, $opt| {
    "${mem} --flag ${opt}"
  }

  # Convert $labels hash to command arguments
  $_labels = $labels.reduce('') |$mem, $label| {
    if $label[1] =~ String {
      "${mem} --label ${label[0]} '${label[1]}'"
    } else {
      $dup = $label[1].reduce('') |$mem2, $value| {
        "${mem2} --${label[0]} '${value}'"
      }
      "${mem} ${dup}"
    }
  }

  $_gateway = $gateway ? {
    undef   => '',
    default => "--gateway ${gateway}",
  }

  $_internal = $internal ? {
    true    => '--internal',
    default => '',
  }

  $_ip_range = $ip_range ? {
    undef   => '',
    default => "--ip-range ${ip_range}"
  }

  $_subnet = $subnet ? {
    undef   => '',
    default => "--subnet ${subnet}",
  }

  $_ipv6 = $ipv6 ? {
    true    => '--ipv6',
    default => '',
  }

  # A rootless container network will be defined as the defined user
  if $user != '' {
    # Set default execution environment for the rootless user
    $exec_defaults = {
      user => $user,
      environment => [
        "HOME=${User[$user]['home']}",
        "XDG_RUNTIME_DIR=/run/user/${User[$user]['uid']}",
        "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/${User[$user]['uid']}/bus",
      ],
      cwd         => User[$user]['home'],
    }
    $requires = [
      Podman::Rootless[$user],
      Service['podman systemd-logind'],
    ]
  } else {
    $exec_defaults = {}
    $requires = []
  }

  case $ensure {
    'present': {
      exec { "podman_create_network_${title}":
        command => @("END"/L),
                  podman network create ${title} --driver ${driver} ${_opts} \
                    ${_gateway} ${_internal} ${_ip_range} ${_labels} ${_subnet} ${_ipv6}
                  |END
        unless  => "podman network exists ${title}",
        path    => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
        require => $requires,
        *       => $exec_defaults,
      }
    }
    'absent': {
      exec { "podman_remove_network_${title}":
        command => "podman network rm ${title}",
        onlyif  => "podman network exists ${title}",
        path    => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
        require => $requires,
        *       => $exec_defaults,
      }
    }
    default: {
      fail('"ensure" must be "present" or "absent"')
    }
  }
}