From: Frank Brehm Date: Thu, 23 Nov 2023 16:08:49 +0000 (+0100) Subject: Integrating update NetworkManager config and making vsphere_tag and vsphere_tag_categ... X-Git-Tag: 1.8.0^2~2 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=0f14d83241f1d2fb259d0d0ff3c85e1247d5a4e0;p=pixelpark%2Fcreate-terraform.git Integrating update NetworkManager config and making vsphere_tag and vsphere_tag_category from a resource to data --- diff --git a/lib/cr_tf/handler/files.py b/lib/cr_tf/handler/files.py index 4fd1b10..d73b470 100644 --- a/lib/cr_tf/handler/files.py +++ b/lib/cr_tf/handler/files.py @@ -28,7 +28,7 @@ from ..errors import AbortExecution from ..xlate import XLATOR -__version__ = '0.5.2' +__version__ = '0.5.3' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -501,19 +501,13 @@ class CrTfHandlerFilesMixin(): 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( @@ -682,7 +676,7 @@ class CrTfHandlerFilesMixin(): 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('''\ @@ -780,6 +774,7 @@ class CrTfHandlerFilesMixin(): 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') @@ -875,8 +870,8 @@ class CrTfHandlerFilesMixin(): 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) @@ -974,24 +969,34 @@ class CrTfHandlerFilesMixin(): # -------------------------------------------------------------------------· 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" @@ -1002,7 +1007,7 @@ class CrTfHandlerFilesMixin(): }} }} - '''), ' ').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} " @@ -1043,12 +1048,22 @@ class CrTfHandlerFilesMixin(): # -------------------------------------------------------------------------· 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" @@ -1059,7 +1074,7 @@ class CrTfHandlerFilesMixin(): }} }} - '''), ' ').format(h=vm.fqdn, k=self.private_key_rel) + '''), ' ').format(commands=commands, h=vm.fqdn, k=self.private_key_rel) return content