cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #04261
[Merge] ~d-info-e/cloud-init:salt-freebsd-patch into cloud-init:master
do3meli has proposed merging ~d-info-e/cloud-init:salt-freebsd-patch into cloud-init:master.
Commit message:
make salt minion module working on FreeBSD.
Previously the module was not working under FreeBSD due to a different package name and some different paths. The module can now be better configured via corresponding config variables in the distro classes.
LP: #1721503
Requested reviews:
cloud-init commiters (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~d-info-e/cloud-init/+git/cloud-init/+merge/340112
the salt minion module was not really usable on FreeBSD so far. I have adjusted/extended the module with some more config variables that can be set based on the distro for better flexibility and compatibility between different distributions. In particular on FreeBSD system paths, package names and service names are different than on other operating systems. This fixes LP: #1721503
--
Your team cloud-init commiters is requested to review the proposed merge of ~d-info-e/cloud-init:salt-freebsd-patch into cloud-init:master.
diff --git a/cloudinit/config/cc_salt_minion.py b/cloudinit/config/cc_salt_minion.py
index 5112a34..6e14a99 100644
--- a/cloudinit/config/cc_salt_minion.py
+++ b/cloudinit/config/cc_salt_minion.py
@@ -55,15 +55,17 @@ def handle(name, cfg, cloud, log, _args):
salt_cfg = cfg['salt_minion']
# Start by installing the salt package ...
- cloud.distro.install_packages(('salt-minion',))
+ pkg_name = cloud.distro.get_option('salt_minion_pkg', 'salt-minion')
+ cloud.distro.install_packages((pkg_name,))
# Ensure we can configure files at the right dir
- config_dir = salt_cfg.get("config_dir", '/etc/salt')
+ os_conf_dir = cloud.distro.get_option('salt_minion_conf_dir', '/etc/salt')
+ config_dir = salt_cfg.get("config_dir", os_conf_dir)
util.ensure_dir(config_dir)
# ... and then update the salt configuration
if 'conf' in salt_cfg:
- # Add all sections from the conf object to /etc/salt/minion
+ # Add all sections from the conf object to minion config file
minion_config = os.path.join(config_dir, 'minion')
minion_data = util.yaml_dumps(salt_cfg.get('conf'))
util.write_file(minion_config, minion_data)
@@ -76,10 +78,10 @@ def handle(name, cfg, cloud, log, _args):
# ... copy the key pair if specified
if 'public_key' in salt_cfg and 'private_key' in salt_cfg:
- if os.path.isdir("/etc/salt/pki/minion"):
- pki_dir_default = "/etc/salt/pki/minion"
+ if os.path.isdir(config_dir + "/pki/minion"):
+ pki_dir_default = config_dir + "/pki/minion"
else:
- pki_dir_default = "/etc/salt/pki"
+ pki_dir_default = config_dir + "/pki"
pki_dir = salt_cfg.get('pki_dir', pki_dir_default)
with util.umask(0o77):
@@ -89,8 +91,14 @@ def handle(name, cfg, cloud, log, _args):
util.write_file(pub_name, salt_cfg['public_key'])
util.write_file(pem_name, salt_cfg['private_key'])
+ # we need to have the salt minion service enabled in rc in order to be
+ # able to start the service. this does only apply on freebsd servers.
+ if cloud.distro.osfamily == 'freebsd':
+ cloud.distro.updatercconf('salt_minion_enable', 'YES')
+
# restart salt-minion. 'service' will start even if not started. if it
# was started, it needs to be restarted for config change.
- util.subp(['service', 'salt-minion', 'restart'], capture=False)
+ srvname = cloud.distro.get_option('salt_minion_service', 'salt-minion')
+ util.subp(['service', srvname, 'restart'], capture=False)
# vi: ts=4 expandtab
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index aa468bc..3af9da5 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -41,6 +41,9 @@ class Distro(distros.Distro):
self.osfamily = 'freebsd'
self.ipv4_pat = re.compile(r"\s+inet\s+\d+[.]\d+[.]\d+[.]\d+")
cfg['ssh_svcname'] = 'sshd'
+ cfg['salt_minion_pkg'] = 'py27-salt'
+ cfg['salt_minion_conf_dir'] = '/usr/local/etc/salt'
+ cfg['salt_minion_service'] = 'salt_minion'
# Updates a key in /etc/rc.conf.
def updatercconf(self, key, value):
diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
index fad1184..cf2e240 100644
--- a/config/cloud.cfg.tmpl
+++ b/config/cloud.cfg.tmpl
@@ -113,9 +113,9 @@ cloud_final_modules:
{% if variant not in ["freebsd"] %}
- puppet
- chef
- - salt-minion
- mcollective
{% endif %}
+ - salt-minion
- rightscale_userdata
- scripts-vendor
- scripts-per-once
Follow ups