Ejemplo n.º 1
0
	def install(self):
		""" Method used to install, link, update puppet client.
		"""
		c = Common()
		c.banner()
		c.client_hosts()

		hostname = Hostname()
		hostname.check()

		l = Logger(c.client_name())

		reader = open(self.logfile)
		startline = len(reader.readlines())

		l.event_counter(startline)

		try:
			operatingSystem = run("/bin/cat /etc/issue | /usr/bin/awk '{print $1}'")

			if(operatingSystem=='Debian'):
				run('aptitude -y update && aptitude -y install puppet')
			else:
				print '--->\tOS not supported'
				sys.exit(0)

			puppetthread = AddCert()
			puppetthread.start()

			puppetthread.join()

		except Exception, e:
			print 'error :', e
Ejemplo n.º 2
0
	def run(self):
		"""
		"""
		c = Common()

		sleep(3)
		subprocess.call(['/usr/sbin/puppetca', '--sign', '%s.%s' % (c.client_name(),self.domain)])
Ejemplo n.º 3
0
	def run(self):
		""" Method used to validate the certificats and update the puppet client.
		"""
		c = Common()
		result = self.checkCertificate()

		l = Logger(c.client_name())

		try:
			if result:
				with hide('warnings','stderr'):
					print '\n[+]--> %s is already linked to the master <--\n' % c.client_name()

					if exists('/etc/.hg'):
						print '[+]--> Configuration files is going to be saved by etckeeper <--\n'
						run('/usr/sbin/etckeeper commit \"Commit by puppet\"')

					runCacher = run('puppet agent --server %s --test' % self.puppet_server)
					runSplit = string.split(runCacher,'\n')

					for runLine in runSplit:
						fullString = '%s - %s' % (c.client_name(),runLine)
						l.logx(fullString)

					l.logx('-'*70)

			else:
				print '\n[-]--> %s is not linked to the master\n' % c.client_name()

				validcertificate = ValidCert()
				validcertificate.start()

				with hide('warnings'):
					run('puppet agent --server %s --waitforcert 3 --test' % self.puppet_server)

				validcertificate.join()

		except Exception, e:
			print 'error :', e
Ejemplo n.º 4
0
	def checkCertificate(self):
		""" Method used to check if the host is already linked on master on not.
		return 'False' or 'True'.
		"""
		c = Common()

		try:
			checkCert = subprocess.Popen(['/usr/sbin/puppetca', '-la'],stdout=subprocess.PIPE)
			checkCertPIPE = checkCert.communicate()[0]
			clientCert = re.search('.*\+.*%s\.%s' % (c.client_name(),self.re_domain), checkCertPIPE)

		except Exception, e:
			print 'error :', e
Ejemplo n.º 5
0
	def remove(self):
		""" Method used to remove puppet, erase custom facts on puppet client.
		"""
		c = Common()
		c.banner()
		c.client_hosts()

		operatingSystem = run("/bin/cat /etc/issue | /usr/bin/awk '{print $1}'")

		if(operatingSystem=='Debian'):
			run('aptitude -y purge puppet')
			run('find /var/lib/puppet -type f -print0 | xargs -0r rm')
		else:
			print '--->\tOS not supported'
			sys.exit(0)

		try:
			subprocess.call(['/usr/sbin/puppetca', '--clean', '%s.%s' % (c.client_name(),self.domain)])
		except Exception, e:
			print 'error :', e
			pass
Ejemplo n.º 6
0
	def update_host(self):
		""" Method used to apply/noop updates on a specific host.
		"""
		c = Common()
		l = Logger(c.client_name())

		try:

			if self.__noop!='apply':
				self.noop_puppet()

			else:
				updatePuppet = AddCert()
				updatePuppet.start()
				updatePuppet.join()

				print '\n' + '-'*60 + '\n'
				return 0

		except Exception, e:
			print 'error :', e
Ejemplo n.º 7
0
			start += 1

		if self.__notification_required:
			self.notification('Error(s)',streamOutput.getvalue())

		print 'Warning(s) during execution :', self.__countwarn
		print 'Error(s) during execution :', self.__counterr

	def remove_color(self,input):
		"""
		"""
		pattern = re.compile('\033\[[0-9;]+m')
		output = re.sub(pattern,'',input)

		return output

	def log_parser(self):
		"""
		"""
		self.event_counter('0')

if __name__ == "__main__":
	"""
	"""
	c = Common()
	env.host_string='puppet-client'

	l = Logger(c.client_name())
	l.log_parser()