brietmax
Contributor
Contributor

Add user to Ubuntu blueprint

Hello 

I have an Ubuntu blueprint With vmware tools install all thé customisation IS ok but i tries to add a custom propertie to enter a user n'aime and password and add thème to a New user on thé déployed serveur With no success

Can you help me

 

 

 

 

0 Kudos
16 Replies
bdamian
Expert
Expert

Are you using and Ubuntu template with Cloud-Init?


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
Tags (1)
0 Kudos
brietmax
Contributor
Contributor

I use Ubuntu template With the vmware tools and all the network config and os config IS throught vmware tools and vsphere customisation file

0 Kudos
bdamian
Expert
Expert

I should say that is possible to add a new user to an ubuntu server through VMware Tools in post provision. But let me tell you, with Cloud-Init this is by far more simple.

With cloud-init you just need to add a couple of lines in the Cloud Template.

With only vmware tools, you need a subscription to vRealize Orchestrator workflow, use an Action with PowerShell and you also need vCenter Credentials + Ubuntu credentials to execute the commands.


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
brietmax
Contributor
Contributor

 
0 Kudos
brietmax
Contributor
Contributor

I will install it and try With i will search how to do 

0 Kudos
bdamian
Expert
Expert

This is my Template which adds a user to an Ubuntu server:

formatVersion: 1
inputs:
  username:
    type: string
    title: Username
    description: Default user
  password:
    type: string
    title: Password
    description: Ingrese una contraseña
    writeOnly: true
resources:
  Cloud_Machine_1:
    type: Cloud.Machine
    properties:
      image: Ubuntu 20.04 Cloud
      flavor: small
      constraints:
        - tag: 'env:dev'
      cloudConfig: |
        #cloud-config
        hostname: ubuntu-dev
        ssh_pwauth: yes
        groups:
          - ${input.username}
        users:
          - default 
          - name: ${input.username}
            primary-group: ${input.username}
            groups: [sudo]
            lock_passwd: false
            sudo: ['ALL=(ALL) NOPASSWD:ALL']
            shell: '/bin/bash'
        chpasswd:
          list: |
            ${input.username}:${input.password}
          expire: false
        runcmd:
          - echo "Defaults:${input.username} !requiretty" >> /etc/sudoers.d/${input.username}

---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
Tags (1)
0 Kudos
brietmax
Contributor
Contributor

Hello

I think i have an issue but i don't understand where

My deployment IS ok but on the VM console i have an error no finger print find for the user vra

IS my local user so thé cloud config not apply

0 Kudos
bdamian
Expert
Expert

I understand, my advice is: make a lab with an Ubuntu Cloud Image. Download the OVA file and put it in a Content Library, then use this image in the Image Mapping.

Create the template and remember to use Dynamic IP. Test it, if it works, we can go forward.


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
0 Kudos
brietmax
Contributor
Contributor

hello,

So I downloaded the cloud image and configure the network with the DHCp

all is ok network ok rename hostname ok and create user ok

now I tried to configured to used my IPAM but I can't reach a network ip

regards

0 Kudos
bdamian
Expert
Expert

As I told you before, cloud-init do not support static IP. So you have 2 choices to change the IP:

  1. Use an external configuration tool like Ansible, Puppet or Saltstack
  2. Try to combine your template with a ConfigurationSpec from vCenter. 

I've tested option 2 with a Windows template. Just create a new ConfigurationSpec for your OS, take your template, change dynamic for static IP and add the ConfigSpec. I havent tested on Ubuntu dough.


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
brietmax
Contributor
Contributor

ok but when I use the vcenter customspec the cloud-init doen't work

perhaps i miss a config

regards

0 Kudos
bdamian
Expert
Expert

I've tested it with a Windows template. I will try with Ubuntu.


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
0 Kudos
brietmax
Contributor
Contributor

ok so i had somes tests

all is ok.

I had forgot one parameter on cloud.cfg

 

thanks for your help

0 Kudos
carl1
Expert
Expert

So Cloud-init and Custom Specs are in-compatible.  The problem is that the cust spec will reboot the VM while cloud-init is still working.  And, cloud-init only runs once.  So you may loose some setup.  If you want to know how to get cloud-init to set the IP,

https://vnuggets.com/2020/01/29/vra-with-cloud-init-and-static-networking/

Good article.

Carl L.

0 Kudos
bdamian
Expert
Expert

Hi Carl,

That solution doesn't work with Ubuntu.


---
Damián Bacalov
vExpert 2017-2018-2019-2020-2021-2022
https://www.linkedin.com/in/damianbacalov/
twitter @bdamian
Tags (1)
0 Kudos
RobertPr
Contributor
Contributor

I add the static IP Address to Ubuntu 1804 and later with the cloud-init "write_files" module and write the netplan config to the machine. It is important to set the property: customizeGuestOs to false, so the vCenter GuestCustomization will not run.

See the example here (with some code for accessing and speedup):

resources:
  ubuntu:
    type: Cloud.vSphere.Machine
    properties:
      name: '${input.name}'
      image: Ubunut_2004_LTS_OP
      flavor: Bronce
      customizeGuestOs: false
      cloudConfig: |
        #cloud-config
        write_files:
          - path: /etc/netplan/99-installer-config.yaml
            content: |
              network:
                version: 2
                renderer: networkd
                ethernets:
                  ens192:
                    addresses:
                      - ${resource.ubuntu.networks[0].address}/${resource.Cloud_NSX_Network_1.prefixLength}
                    gateway4: ${resource.Cloud_NSX_Network_1.gateway}
                    nameservers:
                      search: ${resource.Cloud_NSX_Network_1.dnsSearchDomains}
                      addresses: ${resource.Cloud_NSX_Network_1.dns}
        hostname: ${resource.ubuntu.resourceName}
        ssh_pwauth: yes
        users:
          
          - name: ${input.username}
            groups: users
            passwd: ${input.password}
        chpasswd:
          list: |
            root:xyz
          expire: false  
        runcmd:
        - netplan apply
        - sudo sed -e 's/.*PasswordAuthentication no.*/PasswordAuthentication yes/' -i /etc/ssh/sshd_config
        - sudo sed -e '/^#PermitRootLogin/s/^.*$/PermitRootLogin yes/' -i /etc/ssh/sshd_config
        - sudo service sshd restart
        - sudo sed -e 's/.*ExecStart=\/lib\/systemd\/systemd-networkd-wait-online.*/ExecStart=\/lib\/systemd\/systemd-networkd-wait-online --timeout 1/' -i /lib/systemd/system/systemd-networkd-wait-online.service
        - sudo cp /lib/systemd/system/systemd-networkd-wait-online.service /etc/systemd/system/
        - touch /etc/cloud/cloud-init.disabled
      networks:
        - network: '${resource.Cloud_NSX_Network_1.id}'
          assignment: static