This message was deleted.
# terraform-provider-rancher2
a
This message was deleted.
a
Syntax appears OK. If you’re looking to configure IP addresses from a Network Protocol Profile, you can reference the example HERE
m
Thanks for sharing @adventurous-battery-36116 - My issue ended up being my needing to replace ":" with "=" to seperate the key/values. From:
Copy code
"guestinfo.interface.0.ip.0.address:ip:vswitch-pg"
To:
Copy code
"guestinfo.interface.0.ip.0.address=ip:vswitch-pg"
I did get the properties to work as intended after making this change. I just need to get the cloud-init to run as expected. I will spend some time on this today. Last week it wasnt running at all seemingly so I was never getting the IP at the OS level, but the properties looked good in the vapp settings.
a
Excellent! There's a cloud-init example using Netplan in that same repo under the files/ directory
m
@adventurous-battery-36116 - unfortunately I am still having issues with passing in my cloud_config. I have validated that the file does not contain syntax errors with cloud-init, but still I get the following message when trying to pass it in:
Copy code
failureMessage": "Failure detected from referenced resource <http://rke-machine.cattle.io/v1|rke-machine.cattle.io/v1>, Kind=VmwarevsphereMachine with name \"test-blue-control-6ca3f5f1-wqzgg\": [cmdCreateInner] could not alter cloud-init file: existing userdata file does not begin with '#!' or '#cloud-config'"
Here is a copy of my cloud-config.yml:
Copy code
#cloud-config
write_files:
- content: |
    #!/bin/bash
    vmtoolsd --cmd 'info-get guestinfo.ovfEnv' > /tmp/ovfenv
    IPAddress=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.address" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
    SubnetMask=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.ip.0.netmask" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
    Gateway=$(sed -n 's/.*Property oe:key="guestinfo.interface.0.route.0.gateway" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)
    DNS=$(sed -n 's/.*Property oe:key="guestinfo.dns.servers" oe:value="\([^"]*\).*/\1/p' /tmp/ovfenv)

    cat > /etc/netplan/01-netcfg.yaml <<EOF
    network:
      version: 2
      renderer: networkd
      ethernets:
        ens224:
          addresses:
            - $IPAddress/24
          gateway4: $Gateway
          nameservers:
            addresses : [$DNS]
    EOF

    sudo netplan apply
  path: /root/network_config.sh
  permissions: '755'
- content: |
    network: {config: disabled}
  path: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
  permissions: '644'
- content: |
    net.ipv4.conf.all.forwarding=1
    net.ipv6.conf.all.forwarding=1
  path: /etc/sysctl.d/90-rke2.conf
  permissions: '644'
users:
  - default
  - name: username
    plain_text_passwd: 'passwordhere'
    shell: /bin/bash
    groups: wheel
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh_authorized_keys:
      - ecdsa-sha2-nistp521 <keygohere>
runcmd:
  - bash /root/network_config.sh
Do you have any ideas? I am at a bit of a loss. This is pretty much the last thing in the way of me getting this deployment rolling out.
a
existing userdata
is the red flag for me. What are you using for an image and how are you preparing it? Incidentally, you could get rid of the
/etc/sysctl.d/90-rke2.conf
as RKE2 setup will take care of that for you.
Passing into cloud-init any formatting can also be an exercise in frustration. I don’t think it’s the root of any problem in your case, but to make the cloud-init more re-usable and eliminate YAML-in-YAML formatting hellscape as the source of any pain, try using jsonencode like below, instead:
Copy code
write_files:
- path: /etc/cool/example/file
  defer: true
  permissions: "0600"
  content: ${jsonencode(script_file)}
m
@adventurous-battery-36116 - I downloaded the ubuntu cloud image for vsphere (ubuntu 22.04, but also tried 20.04), and I have been using it to deploy other systems as well. It accepts a vApp option to pass in base64 encoded user-data, and this is how I have been able to get it working using the vsphere provider. I tried adding the vapp_property to the rancher2_machine_config_v2 vsphere_config, but it just never runs there either. I tried removing it from there and just passing in the cloud_config and/or cloudinit options and that failed as well. I havent ever seen my user-data make it onto the system when I login post-boot and check in /var/lib/cloud/instances/, though I do see the rancher provided user-data that does the install etc. Nor do I see it mentioned in the cloud-init.log or anything, which is really odd.
I will try to reference the script with jsonencode
Okay, now I am confused. I copy/pasted my exact cloud-config.yml to a manually provisioned cluster using the same template, and it ran properly. Lol Is it expecting a different file type potentially? I checked thefile type to make sure there wasnt some weird line-ending issue, and its ASCII Text (not CRLF).
I was referencing the file as follows:
file("${path.module}/files/cloud-init.yaml")
which should have worked fine, but I went ahead and just tested removing ${path.module}, and just referenced the file as:
Copy code
file("files/cloud-init.yaml")
and now its working. user error.
🎉 1
131 Views