Merge ~harlowja/cloud-init:tpl-cloud-cfg into cloud-init:master

Proposed by Joshua Harlow on 2016-10-03
Status: Merged
Merge reported by: Scott Moser
Merged at revision: 8a445f0811e8deca935f5781a84e8d08067b1b1e
Proposed branch: ~harlowja/cloud-init:tpl-cloud-cfg
Merge into: cloud-init:master
Diff against target: 545 lines (+266/-96)
6 files modified
Makefile (+5/-2)
cloudinit/util.py (+33/-6)
config/cloud.cfg.tpl (+198/-0)
dev/null (+0/-88)
packages/redhat/cloud-init.spec.in (+4/-0)
tools/render-ud (+26/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Needs Fixing on 2017-03-06
Scott Moser 2016-10-03 Needs Fixing on 2016-11-02
Review via email: mp+307485@code.launchpad.net

Commit Message

Make config/cloud.cfg a template

Certain settings in cloud.cfg don't make sense on different and/or other
distros, and certain modules are routinely being not applied by various
downstream distributors so to aid in this split of cloud.cfg that is
happening downstream anyways we might as well turn cloud.cfg into a
template that all can share and customize (if needed) for certain distros
(this makes it easier to identify common themes and differences and
resolve those).

This change does just that and adjust needed other tooling to correctly
know how to include the renamed and new cloud.cfg files.

To post a comment you must log in.
Scott Moser (smoser) wrote :

Largely seems ok.

A few things though:
 a.) seems unrelated to modify the rpm spec
 b.) what about setup.py?
 c.) shouldnt' we 'git ignore config/cloud.cfg' ?

Scott Moser (smoser) :
review: Needs Fixing
Scott Moser (smoser) wrote :

please drop the unrelated change.

review: Needs Fixing (continuous-integration)
Scott Moser (smoser) wrote :

This needs
a.) rebase
b.) droping of unrelated rpm spec change
c.) check to see that all rendered is as expected.

Scott Moser (smoser) wrote :

Hi,
I've kind of taken this over at
 https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+ref/feature/tpl-cloud-cfg

I'll move this to work in progress.

Scott Moser (smoser) wrote :

Marked this merged. the general templatizatio of cloud.cfg is done now.
thanks for your initial work Josh.

Scott Moser (smoser) wrote :

Marked this merged. the general templatizatio of cloud.cfg is done now.
thanks for your initial work Josh.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/Makefile b/Makefile
2index 5d35dcc..496f1e9 100644
3--- a/Makefile
4+++ b/Makefile
5@@ -66,6 +66,9 @@ check_version:
6 "not equal to code version $(CODE_VERSION)"; exit 2; \
7 else true; fi
8
9+config/cloud.cfg:
10+ ./tools/render-ud config/cloud.cfg.tpl > config/cloud.cfg
11+
12 clean_pyc:
13 @find . -type f -name "*.pyc" -delete
14
15@@ -75,10 +78,10 @@ clean: clean_pyc
16 yaml:
17 @$(CWD)/tools/validate-yaml.py $(YAML_FILES)
18
19-rpm:
20+rpm: config/cloud.cfg
21 ./packages/brpm --distro $(distro)
22
23-deb:
24+deb: config/cloud.cfg
25 ./packages/bddeb
26
27 .PHONY: test pyflakes pyflakes3 clean pep8 rpm deb yaml check_version
28diff --git a/cloudinit/util.py b/cloudinit/util.py
29index eb3e589..cba1ff0 100644
30--- a/cloudinit/util.py
31+++ b/cloudinit/util.py
32@@ -579,13 +579,40 @@ def get_cfg_option_int(yobj, key, default=0):
33
34
35 def system_info():
36- return {
37- 'platform': platform.platform(),
38- 'release': platform.release(),
39- 'python': platform.python_version(),
40- 'uname': platform.uname(),
41- 'dist': platform.linux_distribution(),
42+ info = {
43+ 'platform': platform.platform(),
44+ 'release': platform.release(),
45+ 'python': platform.python_version(),
46+ 'uname': platform.uname(),
47+ 'dist': platform.linux_distribution(),
48 }
49+ plat = info['platform'].lower()
50+ # Try to get more info about what it actually is, in a format
51+ # that we can easily use across linux and variants...
52+ if plat.startswith('darwin'):
53+ info['variant'] = 'darwin'
54+ elif plat.endswith("bsd"):
55+ info['variant'] = 'bsd'
56+ elif plat.startswith('win'):
57+ info['variant'] = 'windows'
58+ elif 'linux' in plat:
59+ # Try to get a single string out of these...
60+ linux_dist, _version, _id = info['dist']
61+ linux_dist = linux_dist.lower()
62+ if linux_dist in ('ubuntu', 'linuxmint', 'mint'):
63+ info['variant'] = 'ubuntu'
64+ else:
65+ for prefix, variant in [('redhat', 'rhel'),
66+ ('centos', 'rhel'),
67+ ('fedora', 'fedora'),
68+ ('debian', 'debian')]:
69+ if linux_dist.startswith(prefix):
70+ info['variant'] = variant
71+ if 'variant' not in info:
72+ info['variant'] = 'linux'
73+ if 'variant' not in info:
74+ info['variant'] = 'unknown'
75+ return info
76
77
78 def get_cfg_option_list(yobj, key, default=None):
79diff --git a/config/cloud.cfg b/config/cloud.cfg
80deleted file mode 100644
81index d608dc8..0000000
82--- a/config/cloud.cfg
83+++ /dev/null
84@@ -1,116 +0,0 @@
85-# The top level settings are used as module
86-# and system configuration.
87-
88-# A set of users which may be applied and/or used by various modules
89-# when a 'default' entry is found it will reference the 'default_user'
90-# from the distro configuration specified below
91-users:
92- - default
93-
94-# If this is set, 'root' will not be able to ssh in and they
95-# will get a message to login instead as the above $user (ubuntu)
96-disable_root: true
97-
98-# This will cause the set+update hostname module to not operate (if true)
99-preserve_hostname: false
100-
101-# Example datasource config
102-# datasource:
103-# Ec2:
104-# metadata_urls: [ 'blah.com' ]
105-# timeout: 5 # (defaults to 50 seconds)
106-# max_wait: 10 # (defaults to 120 seconds)
107-
108-# The modules that run in the 'init' stage
109-cloud_init_modules:
110- - migrator
111- - ubuntu-init-switch
112- - seed_random
113- - bootcmd
114- - write-files
115- - growpart
116- - resizefs
117- - disk_setup
118- - mounts
119- - set_hostname
120- - update_hostname
121- - update_etc_hosts
122- - ca-certs
123- - rsyslog
124- - users-groups
125- - ssh
126-
127-# The modules that run in the 'config' stage
128-cloud_config_modules:
129-# Emit the cloud config ready event
130-# this can be used by upstart jobs for 'start on cloud-config'.
131- - emit_upstart
132- - ssh-import-id
133- - locale
134- - set-passwords
135- - grub-dpkg
136- - apt-pipelining
137- - apt-configure
138- - ntp
139- - timezone
140- - disable-ec2-metadata
141- - runcmd
142- - byobu
143-
144-# The modules that run in the 'final' stage
145-cloud_final_modules:
146- - snappy
147- - package-update-upgrade-install
148- - fan
149- - landscape
150- - lxd
151- - puppet
152- - chef
153- - salt-minion
154- - mcollective
155- - rightscale_userdata
156- - scripts-vendor
157- - scripts-per-once
158- - scripts-per-boot
159- - scripts-per-instance
160- - scripts-user
161- - ssh-authkey-fingerprints
162- - keys-to-console
163- - phone-home
164- - final-message
165- - power-state-change
166-
167-# System and/or distro specific settings
168-# (not accessible to handlers/transforms)
169-system_info:
170- # This will affect which distro class gets used
171- distro: ubuntu
172- # Default user name + that default users groups (if added/used)
173- default_user:
174- name: ubuntu
175- lock_passwd: True
176- gecos: Ubuntu
177- groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
178- sudo: ["ALL=(ALL) NOPASSWD:ALL"]
179- shell: /bin/bash
180- # Other config here will be given to the distro class and/or path classes
181- paths:
182- cloud_dir: /var/lib/cloud/
183- templates_dir: /etc/cloud/templates/
184- upstart_dir: /etc/init/
185- package_mirrors:
186- - arches: [i386, amd64]
187- failsafe:
188- primary: http://archive.ubuntu.com/ubuntu
189- security: http://security.ubuntu.com/ubuntu
190- search:
191- primary:
192- - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
193- - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
194- - http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
195- security: []
196- - arches: [armhf, armel, default]
197- failsafe:
198- primary: http://ports.ubuntu.com/ubuntu-ports
199- security: http://ports.ubuntu.com/ubuntu-ports
200- ssh_svcname: ssh
201diff --git a/config/cloud.cfg-freebsd b/config/cloud.cfg-freebsd
202deleted file mode 100644
203index be664f5..0000000
204--- a/config/cloud.cfg-freebsd
205+++ /dev/null
206@@ -1,88 +0,0 @@
207-# The top level settings are used as module
208-# and system configuration.
209-
210-syslog_fix_perms: root:wheel
211-
212-# This should not be required, but leave it in place until the real cause of
213-# not beeing able to find -any- datasources is resolved.
214-datasource_list: ['ConfigDrive', 'OpenStack', 'Ec2']
215-
216-# A set of users which may be applied and/or used by various modules
217-# when a 'default' entry is found it will reference the 'default_user'
218-# from the distro configuration specified below
219-users:
220- - default
221-
222-# If this is set, 'root' will not be able to ssh in and they
223-# will get a message to login instead as the above $user (ubuntu)
224-disable_root: false
225-
226-# This will cause the set+update hostname module to not operate (if true)
227-preserve_hostname: false
228-
229-# Example datasource config
230-# datasource:
231-# Ec2:
232-# metadata_urls: [ 'blah.com' ]
233-# timeout: 5 # (defaults to 50 seconds)
234-# max_wait: 10 # (defaults to 120 seconds)
235-
236-# The modules that run in the 'init' stage
237-cloud_init_modules:
238-# - migrator
239- - seed_random
240- - bootcmd
241-# - write-files
242- - growpart
243- - resizefs
244- - set_hostname
245- - update_hostname
246-# - update_etc_hosts
247-# - ca-certs
248-# - rsyslog
249- - users-groups
250- - ssh
251-
252-# The modules that run in the 'config' stage
253-cloud_config_modules:
254-# - disk_setup
255-# - mounts
256- - ssh-import-id
257- - locale
258- - set-passwords
259- - package-update-upgrade-install
260-# - landscape
261- - timezone
262-# - puppet
263-# - chef
264-# - salt-minion
265-# - mcollective
266- - disable-ec2-metadata
267- - runcmd
268-# - byobu
269-
270-# The modules that run in the 'final' stage
271-cloud_final_modules:
272- - rightscale_userdata
273- - scripts-vendor
274- - scripts-per-once
275- - scripts-per-boot
276- - scripts-per-instance
277- - scripts-user
278- - ssh-authkey-fingerprints
279- - keys-to-console
280- - phone-home
281- - final-message
282- - power-state-change
283-
284-# System and/or distro specific settings
285-# (not accessible to handlers/transforms)
286-system_info:
287- distro: freebsd
288- default_user:
289- name: freebsd
290- lock_passwd: True
291- gecos: FreeBSD
292- groups: [wheel]
293- sudo: ["ALL=(ALL) NOPASSWD:ALL"]
294- shell: /bin/tcsh
295diff --git a/config/cloud.cfg.tpl b/config/cloud.cfg.tpl
296new file mode 100644
297index 0000000..831139b
298--- /dev/null
299+++ b/config/cloud.cfg.tpl
300@@ -0,0 +1,198 @@
301+## template:jinja
302+
303+# The top level settings are used as module
304+# and system configuration.
305+
306+{% if platform.variant in ["bsd"] %}
307+syslog_fix_perms: root:wheel
308+{% endif %}
309+
310+# A set of users which may be applied and/or used by various modules
311+# when a 'default' entry is found it will reference the 'default_user'
312+# from the distro configuration specified below
313+users:
314+ - default
315+
316+# If this is set, 'root' will not be able to ssh in and they
317+# will get a message to login instead as the default $user
318+{% if platform.variant in ["bsd"] %}
319+disable_root: false
320+{% else %}
321+disable_root: true
322+{% endif %}
323+
324+# This will cause the set+update hostname module to not operate (if true)
325+preserve_hostname: false
326+
327+# Example datasource config
328+# datasource:
329+# Ec2:
330+# metadata_urls: [ 'blah.com' ]
331+# timeout: 5 # (defaults to 50 seconds)
332+# max_wait: 10 # (defaults to 120 seconds)
333+
334+{% if platform.variant in ["bsd"] %}
335+# This should not be required, but leave it in place until the real cause of
336+# not beeing able to find -any- datasources is resolved.
337+datasource_list: ['ConfigDrive', 'OpenStack', 'Ec2']
338+{% endif %}
339+
340+# The modules that run in the 'init' stage
341+cloud_init_modules:
342+ - migrator
343+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
344+ - ubuntu-init-switch
345+{% endif %}
346+ - seed_random
347+ - bootcmd
348+# Setup disks and filesystems ... before we do much else.
349+ - growpart
350+ - resizefs
351+ - disk_setup
352+ - mounts
353+# (end block of disk/fs modules)
354+{% if platform.variant not in ["bsd"] %}
355+ - write-files
356+{% endif %}
357+ - set_hostname
358+ - update_hostname
359+{% if platform.variant not in ["bsd"] %}
360+ - update_etc_hosts
361+ - ca-certs
362+ - rsyslog
363+{% endif %}
364+ - users-groups
365+ - ssh
366+
367+# The modules that run in the 'config' stage
368+cloud_config_modules:
369+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
370+# Emit the cloud config ready event
371+# this can be used by upstart jobs for 'start on cloud-config'.
372+ - emit_upstart
373+{% endif %}
374+ - ssh-import-id
375+ - locale
376+ - set-passwords
377+{% if platform.variant in ["rhel", "fedora"] %}
378+ - spacewalk
379+ - yum-add-repo
380+{% endif %}
381+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
382+ - grub-dpkg
383+ - apt-pipelining
384+ - apt-configure
385+{% endif %}
386+ - ntp
387+ - timezone
388+ - disable-ec2-metadata
389+ - runcmd
390+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
391+ - byobu
392+{% endif %}
393+
394+# The modules that run in the 'final' stage
395+cloud_final_modules:
396+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
397+ - snappy
398+{% endif %}
399+ - package-update-upgrade-install
400+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
401+ - fan
402+ - landscape
403+ - lxd
404+{% endif %}
405+{% if platform.variant not in ["bsd"] %}
406+ # These are all grouped together (but typically only one of them
407+ # actually is doing anything, since most people don't run many of these
408+ # package/configuration management systems at the same time).
409+ - puppet
410+ - chef
411+ - salt-minion
412+ - mcollective
413+ # (end block of configuration management 'like' modules)
414+{% endif %}
415+ - rightscale_userdata
416+ - scripts-vendor
417+ - scripts-per-once
418+ - scripts-per-boot
419+ - scripts-per-instance
420+ - scripts-user
421+ - ssh-authkey-fingerprints
422+ - keys-to-console
423+ - phone-home
424+ - final-message
425+ - power-state-change
426+
427+# System and/or distro specific settings
428+# (not accessible to handlers/transforms)
429+system_info:
430+ # This will affect which distro class gets used...
431+{% if platform.variant in ["ubuntu"] %}
432+ distro: ubuntu
433+{% elif platform.variant in ["fedora"] %}
434+ distro: fedora
435+{% elif platform.variant in ["debian"] %}
436+ distro: debian
437+{% elif platform.variant in ["rhel"] %}
438+ distro: rhel
439+{% elif platform.variant in ["bsd"] %}
440+ distro: freebsd
441+{% else %}
442+ # Unknown/fallback distro.
443+ distro: ubuntu
444+{% endif %}
445+{% if platform.variant in ["ubuntu", "unknown", "debian"] %}
446+ # Default user name + that default users groups (if added/used)
447+ default_user:
448+ name: ubuntu
449+ lock_passwd: True
450+ gecos: Ubuntu
451+ groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
452+ sudo: ["ALL=(ALL) NOPASSWD:ALL"]
453+ shell: /bin/bash
454+ # Other config here will be given to the distro class and/or path classes
455+ paths:
456+ cloud_dir: /var/lib/cloud/
457+ templates_dir: /etc/cloud/templates/
458+ upstart_dir: /etc/init/
459+ package_mirrors:
460+ - arches: [i386, amd64]
461+ failsafe:
462+ primary: http://archive.ubuntu.com/ubuntu
463+ security: http://security.ubuntu.com/ubuntu
464+ search:
465+ primary:
466+ - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
467+ - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
468+ - http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
469+ security: []
470+ - arches: [armhf, armel, default]
471+ failsafe:
472+ primary: http://ports.ubuntu.com/ubuntu-ports
473+ security: http://ports.ubuntu.com/ubuntu-ports
474+ ssh_svcname: ssh
475+{% elif platform.variant in ["rhel", "fedora"] %}
476+ # Default user name + that default users groups (if added/used)
477+ default_user:
478+ name: fedora
479+ lock_passwd: True
480+ gecos: Fedora Cloud User
481+ groups: [wheel, adm, systemd-journal]
482+ sudo: ["ALL=(ALL) NOPASSWD:ALL"]
483+ shell: /bin/bash
484+ # Other config here will be given to the distro class and/or path classes
485+ paths:
486+ cloud_dir: /var/lib/cloud/
487+ templates_dir: /etc/cloud/templates/
488+ ssh_svcname: sshd
489+{% elif platform.variant in ["bsd"] %}
490+ # Default user name + that default users groups (if added/used)
491+ default_user:
492+ name: freebsd
493+ lock_passwd: True
494+ gecos: FreeBSD
495+ groups: [wheel]
496+ sudo: ["ALL=(ALL) NOPASSWD:ALL"]
497+ shell: /bin/tcsh
498+{% endif %}
499diff --git a/packages/redhat/cloud-init.spec.in b/packages/redhat/cloud-init.spec.in
500index d0ae048..9fb8721 100644
501--- a/packages/redhat/cloud-init.spec.in
502+++ b/packages/redhat/cloud-init.spec.in
503@@ -95,6 +95,10 @@ rm -rf \$RPM_BUILD_ROOT%{python_sitelib}/tests
504 mkdir -p \$RPM_BUILD_ROOT/%{_sharedstatedir}/cloud
505 mkdir -p \$RPM_BUILD_ROOT/%{_libexecdir}/%{name}
506
507+# Remove these for now (not sure if they work)...
508+rm \$RPM_BUILD_ROOT/%{_sysconfdir}/NetworkManager/dispatcher.d/hook-network-manager
509+rm \$RPM_BUILD_ROOT/%{_sysconfdir}/dhcp/dhclient-exit-hooks.d/hook-dhclient
510+
511 #if $systemd
512 mkdir -p \$RPM_BUILD_ROOT/%{_unitdir}
513 cp -p systemd/* \$RPM_BUILD_ROOT/%{_unitdir}
514diff --git a/tools/render-ud b/tools/render-ud
515new file mode 100755
516index 0000000..0af7d3c
517--- /dev/null
518+++ b/tools/render-ud
519@@ -0,0 +1,26 @@
520+#!/usr/bin/env python
521+
522+import os
523+import sys
524+
525+if "avoid-pep8-E402-import-not-top-of-file":
526+ _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
527+ sys.path.insert(0, _tdir)
528+ from cloudinit import templater
529+ from cloudinit import util
530+
531+
532+def main():
533+ fn = sys.argv[1]
534+ tpl_params = {
535+ 'platform': util.system_info(),
536+ }
537+ with open(fn, 'rb') as fh:
538+ contents = fh.read()
539+ contents = (templater.render_string(contents, tpl_params))
540+ print(contents)
541+ util.load_yaml(contents)
542+
543+
544+if __name__ == '__main__':
545+ main()

Subscribers

People subscribed via source and target branches