Hello,
I recently had a request for help completely overriding the users list within the Cloud Init User Data of a virtual machine deployment. Please note this is an edge case requirement. Morpheus automatically configures users within Cloud Init for you, and you should not need to use this approach. It serves as an example for custom Cloud Init User Data only. You should be able to achieve what you need with Users and User Groups in Morpheus.
I will briefly document how you can achieve this below. This assumes prior knowledge of Morpheus Variables, Option Type Inputs and the customOptions variable, Cloud Init User Data and also Morpheus library items.
This example will allow someone to dynamically change the name of the custom user in the User Data during deployment. This can be extended further to support additional users, password configuration and Cypher secrets.
Add the custom user data to the Virtual Image settings for the library item. This could also be set on the Cloud level settings:
Here is the redacted example user data:
users:
- name: <%= customOptions?.name ?: 'taylor' %>
lock-passwd: false
shell: /bin/bash
passwd: <redacted>
sudo: ALL=(ALL) ALL
This will fallback to setting the name to taylor
if the customOption is not specified.
Create a text option type input with name
as the field name:
Add this to the library item configuration, in this example, I add it to the layout:
Now when I deploy the instance using this layout I am presented with a text box to specify a name. The input I specify will be used for the name of the user in the users list.
Thanks,
Chris