def before(manager): deps.append(manager) if 0 == len(manager): return if 1 == len(manager) and manager.name in manager: return if 'apt' == manager.name: m['packages'].add(puppet.Exec('apt-get -q update', before=puppet.Class.ref('apt'))) elif 'yum' == manager.name: m['packages'].add(puppet.Exec('yum makecache', before=puppet.Class.ref('yum')))
def package(manager, package, version): # `apt` and `yum` are easy since they're the default for their # respective platforms. if manager.name in ('apt', 'yum'): m['packages'][manager].add(puppet.Package(package, ensure=version)) # If APT is installing RubyGems, get complicated. This would # make sense to do with Yum, too, but there's no consensus on # where, exactly, you might find RubyGems from Yum. Going # the other way, it's entirely likely that doing this sort of # forced upgrade goes against the spirit of Blueprint itself. match = re.match(r'^rubygems(\d+\.\d+(?:\.\d+)?)$', package) if match is not None and rubygems_update(): m['packages'][manager].add(puppet.Exec('/bin/sh -c "' '/usr/bin/gem%s install --no-rdoc --no-ri ' 'rubygems-update; ' '/usr/bin/ruby%s $(PATH=$PATH:/var/lib/gems/%s/bin ' 'which update_rubygems)"' % (match.group(1)), require=puppet.Package.ref(package))) # RubyGems for Ruby 1.8 is easy, too, because Puppet has a # built in provider. elif 'rubygems1.8' == manager.name or 'rubygems' == manager.name: m['packages'][manager].add(puppet.Package(package, ensure=version, provider='gem')) # Other versions of RubyGems are slightly more complicated. elif re.search(r'ruby', manager.name) is not None: match = re.match(r'^ruby(?:gems)?(\d+\.\d+(?:\.\d+)?)', manager.name) m['packages'][manager].add(puppet.Exec( manager(package, version), creates='%s/%s/gems/%s-%s' % (rubygems_path(), match.group(1), package, version))) # Python works basically like alternative versions of Ruby # but follows a less predictable directory structure so the # directory is not known ahead of time. This just so happens # to be the way everything else works, too. else: m['packages'][manager].add(puppet.Exec( manager(package, version)))
def package(manager, package, version): # `apt` is easy since it's the default. if 'apt' == manager.name or 'rpm' == manager.name: m['packages'][manager].add( puppet.Package(package, ensure=version)) # If APT is installing RubyGems, get complicated. match = re.match(r'^rubygems(\d+\.\d+(?:\.\d+)?)$', package) if match is not None and rubygems_update(): m['packages'][manager].add( puppet.Exec( '/bin/sh -c "' '/usr/bin/gem%s install --no-rdoc --no-ri ' 'rubygems-update; ' '/usr/bin/ruby%s $(PATH=$PATH:/var/lib/gems/%s/bin ' 'which update_rubygems)"' % (match.group(1)), require=puppet.Package.ref(package))) # RubyGems for Ruby 1.8 is easy, too, because Puppet has a # built in provider. elif 'rubygems1.8' == manager.name or 'rubygems' == manager.name: m['packages'][manager].add( puppet.Package(package, ensure=version, provider='gem')) # Other versions of RubyGems are slightly more complicated. elif re.search(r'ruby', manager.name) is not None: match = re.match(r'^ruby(?:gems)?(\d+\.\d+(?:\.\d+)?)', manager.name) m['packages'][manager].add( puppet.Exec( manager(package, version), creates='%s/%s/gems/%s-%s' % (rubygems_path(), match.group(1), package, version))) # Python works basically like alternative versions of Ruby # but follows a less predictable directory structure so the # directory is not known ahead of time. This just so happens # to be the way everything else works, too. else: m['packages'][manager].add( puppet.Exec(manager(package, version)))
def puppet(self): """ Generate Puppet code. """ m = puppet.Manifest(self.name, comment=self.DISCLAIMER) # Set the default `PATH` for exec resources. m.add(puppet.Exec.defaults(path=os.environ['PATH'])) # Extract source tarballs. tree = git.tree(self._commit) for dirname, filename in sorted(self.sources.iteritems()): blob = git.blob(tree, filename) content = git.content(blob) pathname = os.path.join('/tmp', filename) m['sources'].add( puppet.File(pathname, self.name, content, owner='root', group='root', mode='0644', source='puppet:///%s/%s' % (self.name, pathname[1:]))) m['sources'].add( puppet.Exec('tar xf %s' % (pathname), cwd=dirname, require=puppet.File.ref(pathname))) # Place files. if 0 < len(self.files): for pathname, f in sorted(self.files.iteritems()): # Create resources for parent directories and let the # autorequire mechanism work out dependencies. dirnames = os.path.dirname(pathname).split('/')[1:] for i in xrange(len(dirnames)): m['files'].add( puppet.File(os.path.join('/', *dirnames[0:i + 1]), ensure='directory')) # Create the actual file resource. if '120000' == f['mode'] or '120777' == f['mode']: m['files'].add( puppet.File(pathname, None, None, owner=f['owner'], group=f['group'], ensure=f['content'])) continue content = f['content'] if 'base64' == f['encoding']: content = base64.b64decode(content) m['files'].add( puppet.File(pathname, self.name, content, owner=f['owner'], group=f['group'], mode=f['mode'][-4:], ensure='file')) # Install packages. deps = [] def before(manager): deps.append(manager) if 'apt' != manager.name: return if 0 == len(manager): return if 1 == len(manager) and manager.name in manager: return m['packages'].add( puppet.Exec('apt-get -q update', before=puppet.Class.ref('apt'))) def package(manager, package, version): # `apt` is easy since it's the default. if 'apt' == manager.name or 'rpm' == manager.name: m['packages'][manager].add( puppet.Package(package, ensure=version)) # If APT is installing RubyGems, get complicated. match = re.match(r'^rubygems(\d+\.\d+(?:\.\d+)?)$', package) if match is not None and rubygems_update(): m['packages'][manager].add( puppet.Exec( '/bin/sh -c "' '/usr/bin/gem%s install --no-rdoc --no-ri ' 'rubygems-update; ' '/usr/bin/ruby%s $(PATH=$PATH:/var/lib/gems/%s/bin ' 'which update_rubygems)"' % (match.group(1)), require=puppet.Package.ref(package))) # RubyGems for Ruby 1.8 is easy, too, because Puppet has a # built in provider. elif 'rubygems1.8' == manager.name or 'rubygems' == manager.name: m['packages'][manager].add( puppet.Package(package, ensure=version, provider='gem')) # Other versions of RubyGems are slightly more complicated. elif re.search(r'ruby', manager.name) is not None: match = re.match(r'^ruby(?:gems)?(\d+\.\d+(?:\.\d+)?)', manager.name) m['packages'][manager].add( puppet.Exec( manager(package, version), creates='%s/%s/gems/%s-%s' % (rubygems_path(), match.group(1), package, version))) # Python works basically like alternative versions of Ruby # but follows a less predictable directory structure so the # directory is not known ahead of time. This just so happens # to be the way everything else works, too. else: m['packages'][manager].add( puppet.Exec(manager(package, version))) self.walk(before=before, package=package) m['packages'].dep(*[puppet.Class.ref(dep) for dep in deps]) # Strict ordering of classes. deps = [] if 0 < len(self.sources): deps.append('sources') if 0 < len(self.files): deps.append('files') if 0 < len(self.packages): deps.append('packages') m.dep(*[puppet.Class.ref(dep) for dep in deps]) return m