def setup_agent4(hostname=None, domain=None, pc="1", agent_conf="files/puppet-agent.conf", puppetserver=None, proxy_url=None, hosts_file=None): """Setup Puppet 4 agent""" import package, util, config if not hostname: hostname = util.get_hostname() if not domain: domain = util.get_domain() install_puppetlabs_release_package(pc, proxy_url=proxy_url) package.install("puppet-agent") # Use puppetserver value from setting.ini file if none is given on the # command-line. If that fails use the default. if not puppetserver: try: puppetserver = config.get("puppet", "puppetserver") except: puppetserver = None # Add a customized puppet.conf util.put_and_chown(agent_conf, "/etc/puppetlabs/puppet/puppet.conf") if puppetserver: server = puppetserver else: server = "puppet.%s" % domain sudo("puppet config set --section agent server %s" % server) util.set_hostname(hostname + "." + domain) util.add_host_entry(util.get_ip(), hostname, domain) # Optionally add hosts from a separate file. This is useful when the IP of # the puppetmaster as seen from the Puppet agent node does not match its # name in DNS. util.add_host_entries(hosts_file) util.add_to_path("/opt/puppetlabs/bin") run_agent(noop="True", onlychanges="False")
def setup_agent5(hostname=None, domain=None, pc="1", agent_conf="files/puppet-agent5.conf", puppetserver=None, proxy_url=None, hosts_file=None): """Setup Puppet 5 agent""" import package, util, config if not hostname: hostname = util.get_hostname() if not domain: domain = util.get_domain() install_puppetlabs_release_package(pc, proxy_url=proxy_url) package.install("puppet-agent") # Use puppetserver value from setting.ini file if none is given on the command-line. If that fails use the default. if not puppetserver: try: puppetserver = config.get("puppet", "puppetserver") except: puppetserver = None # Add a customized puppet.conf util.put_and_chown(agent_conf, "/etc/puppetlabs/puppet/puppet.conf") if puppetserver: server = puppetserver else: server = "puppet.%s" % domain sudo("puppet config set --section agent server %s" % server) util.set_hostname(hostname + "." + domain) util.add_host_entry(util.get_ip(), hostname, domain) # Optionally add hosts from a separate file. This is useful when the IP of the puppetmaster as seen from the Puppet agent # node does not match its name in DNS. util.add_host_entries(hosts_file) util.add_to_path("/opt/puppetlabs/bin") run_agent(noop="False", onlychanges="False")
def setup_agent4(hostname=None, domain=None, pc="1", agent_conf="files/puppet-agent.conf", proxy_url=None, hosts_file=None): """Setup Puppet 4 agent""" import package, util if not hostname: hostname = util.get_hostname() if not domain: domain = util.get_domain() install_puppetlabs_release_package(pc, proxy_url=proxy_url) package.install("puppet-agent") util.put_and_chown(agent_conf, "/etc/puppetlabs/puppet/puppet.conf") util.set_hostname(hostname + "." + domain) util.add_host_entry("127.0.1.1", hostname, domain) # Optionally add hosts from a separate file. This is useful when the IP of # the puppetmaster does not match its name in DNS. util.add_host_entries(hosts_file) util.add_to_path("/opt/puppetlabs/bin") run_agent(noop="True", onlychanges="False")
def onMessage(self, msg): if 'origin' in msg: if msg['origin'] == 'server' and 'connect' in msg and msg[ 'connect'] == 'user': username = msg['username'] user_session = msg['user_session'] if self.add_user_with_session(username, user_session): for c in self.consumers: c.new_user_session(username, user_session) elif msg['origin'] == 'server' and 'disconnect' in msg and msg[ 'disconnect'] == 'user': username = msg['username'] user_session = msg['user_session'] if self.remove_user_with_session(username, user_session): for c in self.consumers: c.end_user_session(username, user_session) elif msg['origin'] == 'server' and 'hello' in msg: info = msg['yourinfo'] vin = info['vin'] name = info['name'] description = info[ 'description'] # <-- Where should we display this? print_all('Device Name: {}'.format(name)) print_all('Device VIN: {}'.format(vin)) output = set_hostname(name) log.info("Set hostname, output is: {}".format(output)) for c in self.consumers: c.got_message(msg, self.smart_send)
def setup_server4(hostname=None, domain=None, pc="1", forge_modules=["puppetlabs/stdlib", "puppetlabs/concat", "puppetlabs/firewall", "puppetlabs/apt"]): """Setup Puppet 4 server""" import package, util, git, service # Local files to copy over basedir = "/etc/puppetlabs" local_master_conf = "files/puppet-master.conf" remote_master_conf = basedir+"/puppet/puppet.conf" local_hiera_yaml = "files/hiera.yaml" remote_hiera_yaml = basedir+"/code/hiera.yaml" local_fileserver_conf = "files/fileserver.conf" remote_fileserver_conf = basedir+"/puppet/fileserver.conf" local_environments = "files/environments" remote_codedir = basedir+"/code" local_gitignore = "files/gitignore" remote_gitignore = basedir+"/.gitignore" modules_dir = basedir+"/code/environments/production/modules" # Verify that all the local files are in place try: open(local_master_conf) open(local_hiera_yaml) except IOError: print "ERROR: some local config files were missing!" sys.exit(1) # Autodetect hostname and domain from env.host, if they're not overridden # with method parameters if not hostname: hostname = util.get_hostname() if not domain: domain = util.get_domain() # Ensure that clock is correct before doing anything else, like creating SSL # certificates. util.set_clock() # Start the install install_puppetlabs_release_package(pc) package.install("puppetserver") util.put_and_chown(local_master_conf, remote_master_conf) util.put_and_chown(local_hiera_yaml, remote_hiera_yaml) util.put_and_chown(local_fileserver_conf, remote_fileserver_conf) util.put_and_chown(local_gitignore, remote_gitignore) util.add_to_path("/opt/puppetlabs/bin") util.set_hostname(hostname + "." + domain) # "facter fqdn" return a silly name on EC2 without this util.add_host_entry("127.0.1.1", hostname, domain) # Copy over template environments util.put_and_chown(local_environments, remote_codedir) # Add modules from Puppet Forge. These should in my experience be limited to # those which provide new types and providers. In particular puppetlabs' # modules which control some daemon (puppetdb, postgresql, mysql) are # extremely complex, very prone to breakage and nasty to debug. for module in forge_modules: add_forge_module(module) # Git setup git.install() git.init(basedir) if not exists(modules_dir): sudo("mkdir "+modules_dir) git.init(modules_dir) git.add_submodules(basedir=modules_dir) git.add_all(basedir) git.commit(basedir, "Initial commit") # Link hieradata and manifests from production to testing. This keeps the # testing environment identical to the production environment. The modules # directory in testing is separate and may (or may not) contain modules that # override or complement those in production. util.symlink(remote_codedir+"/environments/production/hieradata", remote_codedir+"/environments/testing/hieradata") util.symlink(remote_codedir+"/environments/production/manifests", remote_codedir+"/environments/testing/manifests") # Start puppetserver to generate the CA and server certificates/keys service.start("puppetserver") run_agent(noop="False")
def setup_server4(hostname=None, domain=None, pc="1", forge_modules=[ "puppetlabs/stdlib", "puppetlabs/concat", "puppetlabs/firewall", "puppetlabs/apt" ]): """Setup Puppet 4 server""" import package, util, git, service # Local files to copy over basedir = "/etc/puppetlabs" local_master_conf = "files/puppet-master.conf" remote_master_conf = basedir + "/puppet/puppet.conf" local_hiera_yaml = "files/hiera.yaml" remote_hiera_yaml = basedir + "/code/hiera.yaml" local_fileserver_conf = "files/fileserver.conf" remote_fileserver_conf = basedir + "/puppet/fileserver.conf" local_environments = "files/environments" remote_codedir = basedir + "/code" local_gitignore = "files/gitignore" remote_gitignore = basedir + "/.gitignore" modules_dir = basedir + "/code/environments/production/modules" # Verify that all the local files are in place try: open(local_master_conf) open(local_hiera_yaml) except IOError: print "ERROR: some local config files were missing!" sys.exit(1) # Autodetect hostname and domain from env.host, if they're not overridden # with method parameters if not hostname: hostname = util.get_hostname() if not domain: domain = util.get_domain() # Ensure that clock is correct before doing anything else, like creating SSL # certificates. util.set_clock() # Start the install install_puppetlabs_release_package(pc) package.install("puppetserver") util.put_and_chown(local_master_conf, remote_master_conf) util.put_and_chown(local_hiera_yaml, remote_hiera_yaml) util.put_and_chown(local_fileserver_conf, remote_fileserver_conf) util.put_and_chown(local_gitignore, remote_gitignore) util.add_to_path("/opt/puppetlabs/bin") util.set_hostname(hostname + "." + domain) # "facter fqdn" return a silly name on EC2 without this util.add_host_entry("127.0.1.1", hostname, domain) # Copy over template environments util.put_and_chown(local_environments, remote_codedir) # Add modules from Puppet Forge. These should in my experience be limited to # those which provide new types and providers. In particular puppetlabs' # modules which control some daemon (puppetdb, postgresql, mysql) are # extremely complex, very prone to breakage and nasty to debug. for module in forge_modules: add_forge_module(module) # Git setup git.install() git.init(basedir) if not exists(modules_dir): sudo("mkdir " + modules_dir) git.init(modules_dir) git.add_submodules(basedir=modules_dir) git.add_all(basedir) git.commit(basedir, "Initial commit") # Link hieradata and manifests from production to testing. This keeps the # testing environment identical to the production environment. The modules # directory in testing is separate and may (or may not) contain modules that # override or complement those in production. util.symlink(remote_codedir + "/environments/production/hieradata", remote_codedir + "/environments/testing/hieradata") util.symlink(remote_codedir + "/environments/production/manifests", remote_codedir + "/environments/testing/manifests") # Start puppetserver to generate the CA and server certificates/keys service.start("puppetserver") run_agent(noop="False")