from ..xlate import XLATOR
-__version__ = '0.2.0'
+__version__ = '0.3.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# ## Copying postinstall scripts to VM
- files = ['conf-resolver', 'create-motd']
+ files = ['functions.rc', 'conf-resolver', 'create-motd']
+ if vm.is_rhel:
+ files.append('register-rhel')
if vm.has_puppet:
files.append('init-puppet')
files.append('update-all-packages')
'''), ' ').format(
d=self.script_dir_rel, f=sname, h=vm.fqdn)
+ if vm.is_rhel:
+ if self.verbose > 1:
+ LOG.debug(_("Generating file provisioner for {f!r} of {v!r}.").format(
+ f='rhsm-user-passwd', v=vm.name))
+
+ content += textwrap.indent(textwrap.dedent('''\
+ provisioner "file" {{
+ destination = "/tmp/rhsm-user-passwd"
+ content = "${{var.rhsm_user_password}}"
+ connection {{
+ type = "ssh"
+ user = "root"
+ host = "{h}"
+ }}
+ }}
+
+ '''), ' ').format(h=vm.fqdn)
+
# ## Postinstall commands on host
commands = []
else:
cmd += ' --options {!r}'.format('')
commands.append(cmd)
- commands.append("rm -f /tmp/conf-resolver")
+ commands.append("rm -fv /tmp/conf-resolver")
purpose = self.re_doublequote.sub('\\\"', vm.purpose)
commands.append("chmod +x /tmp/create-motd")
cmd = (
"/tmp/create-motd --purpose '{p}' --hardware 'vmware (x86_64)' --owner '{o}' "
- "--location 'VMWare' --zone '{z}' --customer '{c}' --email '{m}' --tier '{t}' "
+ "--location 'VMWare' --zone '{z}' --customer '{c}' --email '{m}' --tier '{t}' "
"--environment '{e}' --role '{r}'").format(
p=purpose, t=vm.puppet_tier, o=vm.customer, z=zone, c=vm.puppet_customer,
m=vm.puppet_contact, e=vm.puppet_env, r=vm.puppet_role)
cmd += " --project '{pr}'".format(pr=vm.puppet_project)
cmd += " | tee /etc/motd"
commands.append(cmd)
- commands.append("rm -f /tmp/create-motd")
-
- # ## Backup - Legato networker
- commands.append("systemctl stop networker.service")
- commands.append("rm -rfv /nsr/tmp /nsr/res")
- if vm.has_backup:
- commands.append("mkdir -pv /nsr/res")
- commands.append(
- "if [ ! -f /nsr/res/servers ] ; then "
- "echo 'legato01.pixelpark.com' > /nsr/res/servers; fi")
- commands.append("systemctl start networker.service; sleep 2")
- commands.append("nsrports -S 7937-7999; sleep 2")
- commands.append("systemctl stop networker.service; sleep 2")
- commands.append(
- "systemctl enable networker.service; systemctl start networker.service; sleep 2")
- commands.append("nsrports; sleep 2")
- else:
- commands.append("systemctl disable networker.service")
+ commands.append("rm -fv /tmp/create-motd")
+
+ # ## Registring RHEL on RedHat Subscription Management
+ if vm.is_rhel:
+ commands.append("chmod +x /tmp/register-rhel")
+ commands.append("/tmp/register-rhel -v -U '${var.rhsm_user_name}'")
+ commands.append("rm -fv /tmp/rhsm-user-passwd /tmp/register-rhel")
# ## Configuring and starting puppet
if vm.has_puppet:
p=purpose, t=vm.puppet_tier, o=vm.customer, c=vm.puppet_customer, z=zone,
pr=vm.puppet_project, m=vm.puppet_contact, e=vm.puppet_env, r=vm.puppet_role)
commands.append(cmd)
- commands.append("rm -f /tmp/init-puppet")
+ commands.append("rm -fv /tmp/init-puppet")
content += ' provisioner "remote-exec" {\n'
content += ' inline = [\n'
if vm.has_puppet:
content += self._create_instfile_puppet(vm)
+ # ## Unregistring from RedHat Subscription Management
+ cmd = ('if [ -x /sbin/subscription-manager ] ; then '
+ '/sbin/subscription-manager unregister --no-progress-messages; fi || true')
+ if vm.is_rhel:
+ content += ' provisioner "remote-exec" {\n'
+ content += ' inline = [\n'
+ content += ' "{}"\n'.format(cmd)
+ content += ' ]\n'
+ content += ' when = destroy\n'
+ content += ' connection {\n'
+ content += ' type = "ssh"\n'
+ content += ' user = "root"\n'
+ content += ' host = "{}"\n'.format(vm.fqdn)
+ content += ' }\n'
+ content += ' }\n\n'
+
# ## local SSH cleanup on destroy
content += textwrap.indent(textwrap.dedent('''\
provisioner "local-exec" {{
"/usr/bin/systemctl enable puppet.service",
"chmod +x /tmp/update-all-packages",
"/tmp/update-all-packages",
- "rm -f /tmp/update-all-packages",
+ "rm -fv /tmp/update-all-packages /tmp/functions.rc",
]
connection {{
type = "ssh"
inline = [
"/usr/bin/systemctl stop puppet.service || true",
]
- when = destroy
+ when = destroy
connection {{
type = "ssh"
user = "root"