From fbc01e536cdd023a954703fdc3bbe76df1d9ed1a Mon Sep 17 00:00:00 2001 From: Ben Arblaster Date: Sun, 18 Jan 2015 01:39:35 +0000 Subject: freebsd: add pkg support --- cloudinit/distros/freebsd.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'cloudinit/distros') diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index f1b4a256..10f9e7e0 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import os + from StringIO import StringIO import re @@ -29,6 +31,8 @@ from cloudinit import util from cloudinit.distros import net_util from cloudinit.distros.parsers.resolv_conf import ResolvConf +from cloudinit.settings import PER_INSTANCE + LOG = logging.getLogger(__name__) @@ -367,13 +371,34 @@ class Distro(distros.Distro): LOG.warn("Error running %s: %s", cmd, err) def install_packages(self, pkglist): - return + self.update_package_sources() + self.package_command('install', pkgs=pkglist) - def package_command(self, cmd, args=None, pkgs=None): - return + def package_command(self, command, args=None, pkgs=None): + if pkgs is None: + pkgs = [] + + e = os.environ.copy() + e['ASSUME_ALWAYS_YES'] = 'YES' + + cmd = ['pkg'] + if args and isinstance(args, str): + cmd.append(args) + elif args and isinstance(args, list): + cmd.extend(args) + + if command: + cmd.append(command) + + pkglist = util.expand_package_list('%s-%s', pkgs) + cmd.extend(pkglist) + + # Allow the output of this to flow outwards (ie not be captured) + util.subp(cmd, env=e, capture=False) def set_timezone(self, tz): return def update_package_sources(self): - return + self._runner.run("update-sources", self.package_command, + ["update"], freq=PER_INSTANCE) -- cgit v1.2.3 From 93f5af9f5075a416c65c1d0350c374e16f32f0d5 Mon Sep 17 00:00:00 2001 From: Ben Arblaster Date: Tue, 20 Jan 2015 00:52:04 +0000 Subject: More FreeBSD improvements - Implement set_passwd - Implement set_timezone - Use /bin/tcsh as default user shell (FreeBSD default) - Change default username to freebsd - Enable set-passwords, package-update-upgrade-install and timezone modules - Remove trailing whitespace --- cloudinit/distros/freebsd.py | 20 ++++++++++++++++---- config/cloud.cfg-freebsd | 10 +++++----- 2 files changed, 21 insertions(+), 9 deletions(-) (limited to 'cloudinit/distros') diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 10f9e7e0..c59a074b 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -238,9 +238,21 @@ class Distro(distros.Distro): util.logexc(LOG, "Failed to create user %s", name) raise e - # TODO: def set_passwd(self, user, passwd, hashed=False): - return False + cmd = ['pw', 'usermod', user] + + if hashed: + cmd.append('-H') + else: + cmd.append('-h') + + cmd.append('0') + + try: + util.subp(cmd, passwd, logstring="chpasswd for %s" % user) + except Exception as e: + util.logexc(LOG, "Failed to set password for %s", user) + raise e def lock_passwd(self, name): try: @@ -394,10 +406,10 @@ class Distro(distros.Distro): cmd.extend(pkglist) # Allow the output of this to flow outwards (ie not be captured) - util.subp(cmd, env=e, capture=False) + util.subp(cmd, env=e, capture=False) def set_timezone(self, tz): - return + distros.set_etc_timezone(tz=tz, tz_file=self._find_tz_file(tz)) def update_package_sources(self): self._runner.run("update-sources", self.package_command, diff --git a/config/cloud.cfg-freebsd b/config/cloud.cfg-freebsd index 5ac181ff..be664f5d 100644 --- a/config/cloud.cfg-freebsd +++ b/config/cloud.cfg-freebsd @@ -49,10 +49,10 @@ cloud_config_modules: # - mounts - ssh-import-id - locale -# - set-passwords -# - package-update-upgrade-install + - set-passwords + - package-update-upgrade-install # - landscape -# - timezone + - timezone # - puppet # - chef # - salt-minion @@ -80,9 +80,9 @@ cloud_final_modules: system_info: distro: freebsd default_user: - name: beastie + name: freebsd lock_passwd: True gecos: FreeBSD groups: [wheel] sudo: ["ALL=(ALL) NOPASSWD:ALL"] - shell: /bin/sh + shell: /bin/tcsh -- cgit v1.2.3