from ..xlate import XLATOR
-__version__ = '0.5.2'
+__version__ = '0.5.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
content += tpl.format(tn=tpl_tf_name, n=tname)
tpl = textwrap.dedent('''\
- resource "vsphere_tag_category" "{cid}" {{
- name = "{cname}"
- description = "{cdesc}"
- cardinality = "SINGLE"
- associable_types = [
- "VirtualMachine",
- ]
+ data "vsphere_tag_category" "{cid}" {{
+ name = "{cname}"
}}
- resource "vsphere_tag" "{tid}" {{
+ data "vsphere_tag" "{tid}" {{
name = "{tname}"
- category_id = "${{vsphere_tag_category.{cid}.id}}"
- description = "{tdesc}"
+ category_id = data.vsphere_tag_category.{cid}.id
}}
''').format(
content += ' enable_disk_uuid = "true"\n\n'
if vm.is_rhel:
- content += ' tags = [\n "${{vsphere_tag.{}.id}}"\n ]\n\n'.format(
+ content += ' tags = [\n data.vsphere_tag.{}.id\n ]\n\n'.format(
self.config.vsphere_tag_os_rhel_id)
content += textwrap.indent(textwrap.dedent('''\
files = ['functions.rc', 'conf-resolver', 'create-motd']
if vm.is_rhel:
files.append('register-rhel')
+ files.append('update-networkmanager')
if vm.has_puppet:
files.append('init-puppet')
files.append('update-all-packages')
cmd += "--project '{pr}' "
cmd += "--role '{r}' --owner '{o}' --tier '{t}' --purpose '{p}' --email '{m}'"
cmd += " --zone '{z}'"
- if vm.puppet_initial_install:
- cmd += " --initial-install"
+ # if vm.puppet_initial_install:
+ # cmd += " --initial-install"
cmd = cmd.format(
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)
# -------------------------------------------------------------------------·
def _create_instfile_puppet(self, vm):
- cmd = (
+ ca_cmd = (
"ssh -o StrictHostKeyChecking=no {ca} "
"'sudo /opt/puppetlabs/bin/puppetserver ca sign --certname {h} || true'").format(
ca=self.config.puppetca, h=vm.fqdn)
+ command_list = [
+ "/opt/puppetlabs/bin/puppet agent --test || true",
+ "/usr/bin/systemctl start puppet.service",
+ "/usr/bin/systemctl enable puppet.service",
+ "chmod +x /tmp/update-all-packages",
+ "/tmp/update-all-packages",
+ "rm -fv /tmp/update-all-packages",
+ ]
+ if vm.is_rhel:
+ command_list.append("chmod +x /tmp/update-networkmanager")
+ command_list.append("/tmp/update-networkmanager -v")
+ command_list.append("rm -fv /tmp/update-networkmanager")
+ command_list.append("rm -fv /tmp/functions.rc")
+ commands=',\n '.join(map( lambda x: '"' + x + '"', command_list))
+
content = textwrap.indent(textwrap.dedent('''\
provisioner "local-exec" {{
- command = "{cmd}"
+ command = "{ca_cmd}"
}}
provisioner "remote-exec" {{
inline = [
- "/opt/puppetlabs/bin/puppet agent --test || true",
- "/usr/bin/systemctl start puppet.service",
- "/usr/bin/systemctl enable puppet.service",
- "chmod +x /tmp/update-all-packages",
- "/tmp/update-all-packages",
- "rm -fv /tmp/update-all-packages /tmp/functions.rc",
+ {commands},
]
connection {{
type = "ssh"
}}
}}
- '''), ' ').format(cmd=cmd, h=vm.fqdn, k=self.private_key_rel)
+ '''), ' ').format(ca_cmd=ca_cmd, commands=commands, h=vm.fqdn, k=self.private_key_rel)
# Destroy actions with puppet
cmd1 = "ssh -o StrictHostKeyChecking=no {ma} "
# -------------------------------------------------------------------------·
def _only_update_packages(self, vm):
+ command_list = [
+ "chmod +x /tmp/update-all-packages",
+ "/tmp/update-all-packages",
+ "rm -fv /tmp/update-all-packages",
+ ]
+ if vm.is_rhel:
+ command_list.append("chmod +x /tmp/update-networkmanager")
+ command_list.append("/tmp/update-networkmanager -v")
+ command_list.append("rm -fv /tmp/update-networkmanager")
+ command_list.append("rm -fv /tmp/functions.rc")
+ commands=',\n '.join(map( lambda x: '"' + x + '"', command_list))
+
content = textwrap.indent(textwrap.dedent('''\
provisioner "remote-exec" {{
inline = [
- "chmod +x /tmp/update-all-packages",
- "/tmp/update-all-packages",
- "rm -fv /tmp/update-all-packages /tmp/functions.rc",
+ {commands},
]
connection {{
type = "ssh"
}}
}}
- '''), ' ').format(h=vm.fqdn, k=self.private_key_rel)
+ '''), ' ').format(commands=commands, h=vm.fqdn, k=self.private_key_rel)
return content