def test_set_rc_config_value(self): bsd_utils.set_rc_config_value('hostname', 'foo') self.write_file.assert_called_with('/etc/rc.conf', 'hostname=foo\n') self.load_file.return_value = RC_FILE.format(hostname='foo') bsd_utils.set_rc_config_value('hostname', 'bar') self.write_file.assert_called_with('/etc/rc.conf', RC_FILE.format(hostname='bar'))
def test_set_rc_config_value(self): bsd_utils.set_rc_config_value("hostname", "foo") self.write_file.assert_called_with("/etc/rc.conf", "hostname=foo\n") self.load_file.return_value = RC_FILE.format(hostname="foo") bsd_utils.set_rc_config_value("hostname", "bar") self.write_file.assert_called_with("/etc/rc.conf", RC_FILE.format(hostname="bar"))
def handle(name, cfg, cloud, log, _args): # If there isn't a salt key in the configuration don't do anything if "salt_minion" not in cfg: log.debug( "Skipping module named %s, no 'salt_minion' key in configuration", name, ) return s_cfg = cfg["salt_minion"] const = SaltConstants(cfg=s_cfg) # Start by installing the salt package ... cloud.distro.install_packages(const.pkg_name) # Ensure we can configure files at the right dir util.ensure_dir(const.conf_dir) # ... and then update the salt configuration if "conf" in s_cfg: # Add all sections from the conf object to minion config file minion_config = os.path.join(const.conf_dir, "minion") minion_data = safeyaml.dumps(s_cfg.get("conf")) util.write_file(minion_config, minion_data) if "grains" in s_cfg: # add grains to /etc/salt/grains grains_config = os.path.join(const.conf_dir, "grains") grains_data = safeyaml.dumps(s_cfg.get("grains")) util.write_file(grains_config, grains_data) # ... copy the key pair if specified if "public_key" in s_cfg and "private_key" in s_cfg: pki_dir_default = os.path.join(const.conf_dir, "pki/minion") if not os.path.isdir(pki_dir_default): pki_dir_default = os.path.join(const.conf_dir, "pki") pki_dir = s_cfg.get("pki_dir", pki_dir_default) with util.umask(0o77): util.ensure_dir(pki_dir) pub_name = os.path.join(pki_dir, "minion.pub") pem_name = os.path.join(pki_dir, "minion.pem") util.write_file(pub_name, s_cfg["public_key"]) util.write_file(pem_name, s_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": bsd_utils.set_rc_config_value("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. subp.subp(["service", const.srv_name, "restart"], capture=False)
def _write_hostname(self, hostname, filename): bsd_utils.set_rc_config_value("hostname", hostname, fn="/etc/rc.conf")
def _write_hostname(self, hostname, filename): bsd_utils.set_rc_config_value('hostname', hostname, fn='/etc/rc.conf')
def set_rc_config_value(self, key, value): fn = subp.target_path(self.target, self.rc_conf_fn) bsd_utils.set_rc_config_value(key, value, fn=fn)