From a2e588b027dd038f029727935ab07c0bacadcdc9 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 15 Jun 2012 17:37:17 -0700 Subject: Added a new transform that can be used to show and initial welcome message to users. It is similar to the final msg one, but is used at the start of cloud init instead. --- templates/welcome_msg.tmpl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 templates/welcome_msg.tmpl (limited to 'templates') diff --git a/templates/welcome_msg.tmpl b/templates/welcome_msg.tmpl new file mode 100644 index 00000000..999202cc --- /dev/null +++ b/templates/welcome_msg.tmpl @@ -0,0 +1,15 @@ + _ + _( )_ + ( ) + (_______) + _ \ \ \ \ + _( )_ _ + ( ) _( )_ +(_______) ( ) + \ \ \ \ (_______) + \ \ \ \ + +Cloud-init v. {{version}} +Starting stage: {{stage}} on {{timestamp}} +System uptime: {{uptime}} seconds +-- -- cgit v1.2.3 From 09f6384ac5694be18bef4872c9f19b9601b48f8b Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 15 Jun 2012 17:39:54 -0700 Subject: Added a hosts template file (in tempita format) that provides the base of a "/etc/hosts" file for rhel like systems. --- templates/hosts.redhat.tmpl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 templates/hosts.redhat.tmpl (limited to 'templates') diff --git a/templates/hosts.redhat.tmpl b/templates/hosts.redhat.tmpl new file mode 100644 index 00000000..cfc40668 --- /dev/null +++ b/templates/hosts.redhat.tmpl @@ -0,0 +1,22 @@ +{{# This file /etc/cloud/templates/hosts.tmpl is only utilized + if enabled in cloud-config. Specifically, in order to enable it + you need to add the following to config: + manage_etc_hosts: True}} +# +# Your system has configured 'manage_etc_hosts' as True. +# As a result, if you wish for changes to this file to persist +# then you will need to either +# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl +# b.) change or remove the value of 'manage_etc_hosts' in +# /etc/cloud/cloud.cfg or cloud-config from user-data +# +# The following lines are desirable for IPv4 capable hosts +127.0.0.1 {{fqdn}} {{hostname}} +127.0.0.1 localhost.localdomain localhost +127.0.0.1 localhost4.localdomain4 localhost4 + +# The following lines are desirable for IPv6 capable hosts +::1 {{fqdn}} {{hostname}} +::1 localhost.localdomain localhost +::1 localhost6.localdomain6 localhost6 + -- cgit v1.2.3 From 19f5aa0f4bb449a826a0e6a96f318dba4d814443 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 15 Jun 2012 17:40:55 -0700 Subject: Renamed hosts to match the ubuntu distro. Also converted all the other templates to tempita format instead of the more complicated (and more dependent on other packages) cheetah format. --- templates/chef_client.rb.tmpl | 8 ++-- templates/default-locale.tmpl | 2 +- templates/hosts.tmpl | 25 ----------- templates/hosts.ubuntu.tmpl | 24 ++++++++++ templates/sources.list.tmpl | 101 +++++++++++++++++++++--------------------- 5 files changed, 79 insertions(+), 81 deletions(-) delete mode 100644 templates/hosts.tmpl create mode 100644 templates/hosts.ubuntu.tmpl (limited to 'templates') diff --git a/templates/chef_client.rb.tmpl b/templates/chef_client.rb.tmpl index d3d9a922..35123ced 100644 --- a/templates/chef_client.rb.tmpl +++ b/templates/chef_client.rb.tmpl @@ -1,12 +1,12 @@ log_level :info log_location "/var/log/chef/client.log" ssl_verify_mode :verify_none -validation_client_name "$validation_name" +validation_client_name "{{validation_name}}" validation_key "/etc/chef/validation.pem" client_key "/etc/chef/client.pem" -chef_server_url "$server_url" -environment "$environment" -node_name "$node_name" +chef_server_url "{{server_url}}" +environment "{{environment}}" +node_name "{{node_name}}" json_attribs "/etc/chef/firstboot.json" file_cache_path "/var/cache/chef" file_backup_path "/var/backups/chef" diff --git a/templates/default-locale.tmpl b/templates/default-locale.tmpl index 7940672b..5ee7e454 100644 --- a/templates/default-locale.tmpl +++ b/templates/default-locale.tmpl @@ -1 +1 @@ -LANG="$locale" +LANG="{{locale}}" diff --git a/templates/hosts.tmpl b/templates/hosts.tmpl deleted file mode 100644 index ae120b02..00000000 --- a/templates/hosts.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -## This file (/etc/cloud/templates/hosts.tmpl) is only utilized -## if enabled in cloud-config. Specifically, in order to enable it -## you need to add the following to config: -## manage_etc_hosts: True -## -## Note, double-hash commented lines will not appear in /etc/hosts -# -# Your system has configured 'manage_etc_hosts' as True. -# As a result, if you wish for changes to this file to persist -# then you will need to either -# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl -# b.) change or remove the value of 'manage_etc_hosts' in -# /etc/cloud/cloud.cfg or cloud-config from user-data -# -## The value '$hostname' will be replaced with the local-hostname -127.0.1.1 $fqdn $hostname -127.0.0.1 localhost - -# The following lines are desirable for IPv6 capable hosts -::1 ip6-localhost ip6-loopback -fe00::0 ip6-localnet -ff00::0 ip6-mcastprefix -ff02::1 ip6-allnodes -ff02::2 ip6-allrouters -ff02::3 ip6-allhosts diff --git a/templates/hosts.ubuntu.tmpl b/templates/hosts.ubuntu.tmpl new file mode 100644 index 00000000..9eebe971 --- /dev/null +++ b/templates/hosts.ubuntu.tmpl @@ -0,0 +1,24 @@ +{{# This file /etc/cloud/templates/hosts.tmpl is only utilized + if enabled in cloud-config. Specifically, in order to enable it + you need to add the following to config: + manage_etc_hosts: True}} +# +# Your system has configured 'manage_etc_hosts' as True. +# As a result, if you wish for changes to this file to persist +# then you will need to either +# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl +# b.) change or remove the value of 'manage_etc_hosts' in +# /etc/cloud/cloud.cfg or cloud-config from user-data +# +# The following lines are desirable for IPv4 capable hosts +127.0.1.1 {{fqdn}} {{hostname}} +127.0.0.1 localhost + +# The following lines are desirable for IPv6 capable hosts +::1 ip6-localhost ip6-loopback +fe00::0 ip6-localnet +ff00::0 ip6-mcastprefix +ff02::1 ip6-allnodes +ff02::2 ip6-allrouters +ff02::3 ip6-allhosts + diff --git a/templates/sources.list.tmpl b/templates/sources.list.tmpl index f702025f..8acbd7d5 100644 --- a/templates/sources.list.tmpl +++ b/templates/sources.list.tmpl @@ -1,60 +1,59 @@ -\## Note, this file is written by cloud-init on first boot of an instance -\## modifications made here will not survive a re-bundle. -\## if you wish to make changes you can: -\## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg -\## or do the same in user-data -\## b.) add sources in /etc/apt/sources.list.d -\## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl -\### +# Note, this file is written by cloud-init on first boot of an instance +# modifications made here will not survive a re-bundle. +# if you wish to make changes you can: +# a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg +# or do the same in user-data +# b.) add sources in /etc/apt/sources.list.d +# c.) make changes to template file /etc/cloud/templates/sources.list.tmpl # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to # newer versions of the distribution. -deb $mirror $codename main -deb-src $mirror $codename main +deb {{mirror}} {{codename}} main +deb-src {{mirror}} {{codename}} main -\## Major bug fix updates produced after the final release of the -\## distribution. -deb $mirror $codename-updates main -deb-src $mirror $codename-updates main +# Major bug fix updates produced after the final release of the +# distribution. +deb {{mirror}} {{codename}}-updates main +deb-src {{mirror}} {{codename}}-updates main -\## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -\## team. Also, please note that software in universe WILL NOT receive any -\## review or updates from the Ubuntu security team. -deb $mirror $codename universe -deb-src $mirror $codename universe -deb $mirror $codename-updates universe -deb-src $mirror $codename-updates universe +# N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +# team. Also, please note that software in universe WILL NOT receive any +# review or updates from the Ubuntu security team. +deb {{mirror}} {{codename}} universe +deb-src {{mirror}} {{codename}} universe +deb {{mirror}} {{codename}}-updates universe +deb-src {{mirror}} {{codename}}-updates universe -\## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu -\## team, and may not be under a free licence. Please satisfy yourself as to -\## your rights to use the software. Also, please note that software in -\## multiverse WILL NOT receive any review or updates from the Ubuntu -\## security team. -# deb $mirror $codename multiverse -# deb-src $mirror $codename multiverse -# deb $mirror $codename-updates multiverse -# deb-src $mirror $codename-updates multiverse +# N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu +# team, and may not be under a free licence. Please satisfy yourself as to +# your rights to use the software. Also, please note that software in +# multiverse WILL NOT receive any review or updates from the Ubuntu +# security team. +# deb {{mirror}} {{codename}} multiverse +# deb-src {{mirror}} {{codename}} multiverse +# deb {{mirror}} {{codename}}-updates multiverse +# deb-src {{mirror}} {{codename}}-updates multiverse -\## Uncomment the following two lines to add software from the 'backports' -\## repository. -\## N.B. software from this repository may not have been tested as -\## extensively as that contained in the main release, although it includes -\## newer versions of some applications which may provide useful features. -\## Also, please note that software in backports WILL NOT receive any review -\## or updates from the Ubuntu security team. -# deb $mirror $codename-backports main restricted universe multiverse -# deb-src $mirror $codename-backports main restricted universe multiverse +# Uncomment the following two lines to add software from the 'backports' +# repository. +# N.B. software from this repository may not have been tested as +# extensively as that contained in the main release, although it includes +# newer versions of some applications which may provide useful features. +# Also, please note that software in backports WILL NOT receive any review +# or updates from the Ubuntu security team. +# deb {{mirror}} {{codename}}-backports main restricted universe multiverse +# deb-src {{mirror}} {{codename}}-backports main restricted universe multiverse -\## Uncomment the following two lines to add software from Canonical's -\## 'partner' repository. -\## This software is not part of Ubuntu, but is offered by Canonical and the -\## respective vendors as a service to Ubuntu users. -# deb http://archive.canonical.com/ubuntu $codename partner -# deb-src http://archive.canonical.com/ubuntu $codename partner +# Uncomment the following two lines to add software from Canonical's +# 'partner' repository. +# This software is not part of Ubuntu, but is offered by Canonical and the +# respective vendors as a service to Ubuntu users. +# deb http://archive.canonical.com/ubuntu {{codename}} partner +# deb-src http://archive.canonical.com/ubuntu {{codename}} partner -deb http://security.ubuntu.com/ubuntu $codename-security main -deb-src http://security.ubuntu.com/ubuntu $codename-security main -deb http://security.ubuntu.com/ubuntu $codename-security universe -deb-src http://security.ubuntu.com/ubuntu $codename-security universe -# deb http://security.ubuntu.com/ubuntu $codename-security multiverse -# deb-src http://security.ubuntu.com/ubuntu $codename-security multiverse +deb http://security.ubuntu.com/ubuntu {{codename}}-security main +deb-src http://security.ubuntu.com/ubuntu {{codename}}-security main +deb http://security.ubuntu.com/ubuntu {{codename}}-security universe +deb-src http://security.ubuntu.com/ubuntu {{codename}}-security universe +# deb http://security.ubuntu.com/ubuntu {{codename}}-security multiverse +# deb-src http://security.ubuntu.com/ubuntu {{codename}}-security multiverse -- cgit v1.2.3 From 5917096c8c686b10cf24a0b4c63eb075726f87df Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 18 Jun 2012 21:05:57 -0700 Subject: 1. Removed the welcome message for now :-) --- config/cloud.cfg | 6 ++---- templates/welcome_msg.tmpl | 15 --------------- 2 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 templates/welcome_msg.tmpl (limited to 'templates') diff --git a/config/cloud.cfg b/config/cloud.cfg index 7a6bf243..b11b5aa5 100644 --- a/config/cloud.cfg +++ b/config/cloud.cfg @@ -21,10 +21,8 @@ preserve_hostname: false # The transform that run in the 'init' stage cloud_init_modules: # This is the hash way of specifying a transform - - name: welcome-message -# This argument list will get passed to the transform when activated - args: - - init + - name: bootcmd +# This is the string way of specifying a transform - bootcmd - resizefs - set-hostname diff --git a/templates/welcome_msg.tmpl b/templates/welcome_msg.tmpl deleted file mode 100644 index 999202cc..00000000 --- a/templates/welcome_msg.tmpl +++ /dev/null @@ -1,15 +0,0 @@ - _ - _( )_ - ( ) - (_______) - _ \ \ \ \ - _( )_ _ - ( ) _( )_ -(_______) ( ) - \ \ \ \ (_______) - \ \ \ \ - -Cloud-init v. {{version}} -Starting stage: {{stage}} on {{timestamp}} -System uptime: {{uptime}} seconds --- -- cgit v1.2.3 From c49507a221464ce0f9747d4371f8e3d1d1b30abd Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 21 Jun 2012 19:46:16 -0700 Subject: Updated so that the locale that is being written out currently in 'cc_locale' now will be done by the distro classes (since its not the same for rhel and ubuntu). Remove the template also since it will just be created by the ubuntu distro class (its just one line). --- cloudinit/config/cc_locale.py | 25 ++----------------------- cloudinit/distros/__init__.py | 4 ++++ cloudinit/distros/rhel.py | 31 +++++++++++++++++++++++++++++++ cloudinit/distros/ubuntu.py | 11 +++++++++++ templates/default-locale.tmpl | 1 - 5 files changed, 48 insertions(+), 24 deletions(-) delete mode 100644 templates/default-locale.tmpl (limited to 'templates') diff --git a/cloudinit/config/cc_locale.py b/cloudinit/config/cc_locale.py index 3fb4c5d9..6feaae9d 100644 --- a/cloudinit/config/cc_locale.py +++ b/cloudinit/config/cc_locale.py @@ -18,41 +18,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import os - -from cloudinit import templater from cloudinit import util -def apply_locale(locale, cfgfile, cloud, log): - # TODO this command might not work on RH... - if os.path.exists('/usr/sbin/locale-gen'): - util.subp(['locale-gen', locale], capture=False) - if os.path.exists('/usr/sbin/update-locale'): - util.subp(['update-locale', locale], capture=False) - if not cfgfile: - return - template_fn = cloud.get_template_filename('default-locale') - if not template_fn: - log.warn("No template filename found to write to %s", cfgfile) - else: - templater.render_to_file(template_fn, cfgfile, {'locale': locale}) - - def handle(name, cfg, cloud, log, args): if len(args) != 0: locale = args[0] else: locale = util.get_cfg_option_str(cfg, "locale", cloud.get_locale()) - locale_cfgfile = util.get_cfg_option_str(cfg, "locale_configfile", - "/etc/default/locale") - if not locale: log.debug(("Skipping module named %s, " "no 'locale' configuration found"), name) return log.debug("Setting locale to %s", locale) - - apply_locale(locale, locale_cfgfile, cloud, log) + locale_cfgfile = util.get_cfg_option_str(cfg, "locale_configfile") + cloud.distro.apply_locale(locale, locale_cfgfile) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index f9a97da7..c324ddf6 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -82,6 +82,10 @@ class Distro(object): return self._interface_action('up') return False + @abc.abstractmethod + def apply_locale(self, locale, out_fn=None): + raise NotImplementedError() + @abc.abstractmethod def set_timezone(self, tz): raise NotImplementedError() diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py index 5cbefa6e..df63d559 100644 --- a/cloudinit/distros/rhel.py +++ b/cloudinit/distros/rhel.py @@ -30,6 +30,10 @@ LOG = logging.getLogger(__name__) NETWORK_FN_TPL = '/etc/sysconfig/network-scripts/ifcfg-%s' +# See: http://tiny.cc/6r99fw +# For what alot of these files that are being written +# are and the format of them + class Distro(distros.Distro): @@ -83,6 +87,33 @@ class Distro(distros.Distro): LOG.debug("Setting hostname to %s", hostname) util.subp(['hostname', hostname]) + def apply_locale(self, locale, out_fn=None): + if not out_fn: + out_fn = self._paths.join(False, '/etc/sysconfig/i18n') + ro_fn = self._paths.join(True, '/etc/sysconfig/i18n') + # Update the 'LANG' if it exists instead of appending + old_contents = self._read_conf(ro_fn) + adjusted = False + new_contents = [] + for entry in old_contents: + if not entry: + continue + if len(entry) == 1: + new_contents.append(entry[0]) + continue + (cmd, args) = entry + cmd_c = cmd.strip().lower() + if cmd_c == 'lang': + args = "%s" % (locale) + adjusted = True + new_contents.append("=".join([cmd, args])) + # Guess not found, append it + if not adjusted: + new_contents.append("# Added by cloud-init") + new_contents.append('LANG="%s"' % (locale)) + contents = "\n".join(new_contents) + util.write_file(out_fn, contents, 0644) + def _write_hostname(self, hostname, out_fn): old_contents = [] if os.path.isfile(out_fn): diff --git a/cloudinit/distros/ubuntu.py b/cloudinit/distros/ubuntu.py index 15af2e7f..e8b95374 100644 --- a/cloudinit/distros/ubuntu.py +++ b/cloudinit/distros/ubuntu.py @@ -41,6 +41,17 @@ class Distro(distros.Distro): # should only happen say once per instance...) self._runner = helpers.Runners(paths) + def apply_locale(self, locale, out_fn=None): + if not out_fn: + out_fn = self._paths.join(False, '/etc/default/locale') + util.subp(['locale-gen', locale], capture=False) + util.subp(['update-locale', locale], capture=False) + contents = [ + "# Created by cloud-init", + 'LANG="%s"' % (locale), + ] + util.write_file(out_fn, "\n".join(contents)) + def install_packages(self, pkglist): self._update_package_sources() self.package_command('install', pkglist) diff --git a/templates/default-locale.tmpl b/templates/default-locale.tmpl deleted file mode 100644 index 5ee7e454..00000000 --- a/templates/default-locale.tmpl +++ /dev/null @@ -1 +0,0 @@ -LANG="{{locale}}" -- cgit v1.2.3