From 15d1df9de4e6f1d5013cf85c87d2cfc6efaf2efc Mon Sep 17 00:00:00 2001 From: Michael Baker Date: Tue, 8 Apr 2025 06:33:01 +0800 Subject: [PATCH] Add systemd support --- README.md | 13 +++++++---- manifests/init.pp | 2 ++ manifests/systemd.pp | 52 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 manifests/systemd.pp diff --git a/README.md b/README.md index fbecd36..eba964d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ httpproxy 5. [Contributors](#contributors) ## Overview -WARNING: This module will default to wiping any proxies in profile.d, apt conf.d, and yum.conf. Pass false to disable +WARNING: This module will default to wiping any proxies in profile.d, apt conf.d, yum.conf and systemd. Pass false to disable the module from handling those software packages. This module was created to streamline proxy management of popular software. It can place and remove @@ -27,6 +27,7 @@ proxies in profile.d, apt, yum, and wget. Currently only http (no https) proxies wget => true, profiled => true, packagemanager => true, + systemd => true, http_proxy => 'my.proxy.com', http_proxy_port => '80' } @@ -35,19 +36,23 @@ Puppet will manage the proxy for the desired software when its boolean is set to puppet will ensure that the proxy is present. If a proxy is left undefined, puppet will remove whatever proxy it placed (ensure absent). If the boolean is set to false, nothing will be removed or placed. -The no_proxy parameter takes a comma separated string of addresses to be ignored by the profile.d proxy. +The no_proxy parameter takes a comma separated string of addresses to be ignored by the profile.d and systemd proxy. ## Reference httpproxy uses the Unibets profile.d management module to manage proxies in profile.d. The puppetlabs/inifile resource is used to manage the yum and wget proxies. The apt proxy is managed via the puppetlabs/apt module. +systemd proxy is managed with file_line. Note the systemd proxy will override any DefaultEnvironment you currently have set in systemd. + Please contribute, pull requests are welcome. The more proxies that can be managed the better. ## Limitations -This module has been tested against Puppet 4, CentOS 5,6,7, and Ubuntu 14.04. +This module has been tested against Puppet 4, CentOS 5,6,7, Oracle Linux 9, and Ubuntu 14.04. ## Contributors -Chris Edester and Michael Callahan +Chris Edester +Michael Callahan +Michael Baker (@elmobp) diff --git a/manifests/init.pp b/manifests/init.pp index a16081f..5ff4cf2 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -7,6 +7,7 @@ $no_proxy = undef, $profiled = true, $packagemanager = true, + $systemd = true, $wget = false, Boolean $purge_apt_conf = false, ){ @@ -36,5 +37,6 @@ # Boolean parameter for class selection if $profiled { contain 'httpproxy::profiled' } if $packagemanager { contain 'httpproxy::packagemanager' } + if $systemd { contain 'httpproxy::systemd' } if $wget { contain 'httpproxy::wget' } } diff --git a/manifests/systemd.pp b/manifests/systemd.pp new file mode 100644 index 0000000..f3d6ca6 --- /dev/null +++ b/manifests/systemd.pp @@ -0,0 +1,52 @@ +# Systemd.pp (private class) +# Manages proxies for systemd under DefaultEnvironment +class httpproxy::profiled { + + $ensure = $httpproxy::systemd ? { + true => $httpproxy::ensure, + default => $httpproxy::systemd, + } + + if $httpproxy::no_proxy { + $lines = [ + "\"HTTP_PROXY=${httpproxy::proxy_uri}\"", + "\"HTTPS_PROXY=${httpproxy::proxy_uri}\"", + "\"NO_PROXY=${httpproxy::no_proxy}\"", + "\"http_proxy=${httpproxy::proxy_uri}\"", + "\"https_proxy=${httpproxy::proxy_uri}\"", + "\"no_proxy=${httpproxy::no_proxy}\"" + ] + } + else { + $lines = [ + "\"HTTP_PROXY=${httpproxy::proxy_uri}\"", + "\"HTTPS_PROXY=${httpproxy::proxy_uri}\"", + "\"http_proxy=${httpproxy::proxy_uri}\"", + "\"https_proxy=${httpproxy::proxy_uri}\"", + ] + } + + $proxy_line = join($lines, ' ') + + if $ensure { + file_line{'systemd-default-proxy': + ensure => present, + match => '^#DefaultEnvironment', + line => "DefaultEnvironment=${proxy_line}", + notify => Exec['reload-systemd-for-proxy'] + } + } else { + file_line{'systemd-default-proxy': + ensure => absent, + match => 'DefaultEnvironment', + notify => Exec['reload-systemd-for-proxy'] + } + } + + exec{'reload-systemd-for-proxy': + command => 'systemctl daemon-reload', + path => ['/usr/local/bin', '/usr/bin', '/bin'], + subscribe => File_Line['systemd-default-proxy'], + refreshonly => true + } +}