setting a non-default username

I known someone asked a long time ago how to change the default “ubuntu” username, something that cloud-init calls “default user”,

Back them there seemed like there was no obvious/easy way to do it.

What is the easiest way to get the new machines with another default user?

Perhaps the username of the MAAS UI could be used instead.

The ubuntu user is defined in the file /etc/cloud/cloud.cfg, by default the Ubuntu/CentOS have his configuration with have already one user created.

The most easy way is edit this file in the SO image. Other solution is edit this file using the curtin_user_data or cludinit deploy scripts (https://maas.io/docs/snap/2.8/ui/custom-machine-setup).

This is a example of cloud.cfg provided by default with CentOS 8:

users:
 - default

[___skipped some lines ___]

system_info:
  default_user:
    name: centos
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
  paths:
    cloud_dir: /var/lib/cloud
    templates_dir: /etc/cloud/templates
  ssh_svcname: sshd

You only need to modify the name: centos by other username.

NOTE: you can write files in the curtin_userdata using this syntax:

write_files:
  cloudconfig:
    path: /etc/cloud/cloud.cfg
    permissions: '0400'
    content: |
        RAW CONTENT HERE
        CAN HAVE MULTIPLE LINES

NOTE2: I recommend to launch an ansible playbook instead write files using curtin.

I see…

I have looked at how we currently do with CloudStack.

Seems like we could not change the default user either. Our current setup is that we have cloud-init create what we call our ops user, and then ansible will continue with the setup, among other tasks will delete the default distribution user/users.

I have yet to get curtin_userdata working. perhaps I can try to add just an user: block in the cloud.cfg.d directory.

I can see that in the next maas release cloud-init is better integrated, it would be nice to easily customize this kind of thing.

I would like to create an inventory plugin that reads from MAAS to nicely tie together both tools, and would also be nice to be able to manage MAAS objects via ansible (networks, tags, etc).

@adolfo94 Here is my first attempt to get curtin_userdata to work for the first time,

Something like a hello world.

My Machine id (shown in MAAS url) is xxxx
It is ubuntu 18.04

So I am creating the following file in /var/snap/maas/current/preseeds

curtin_userdata_ubuntu_amd64_generic_bionic_xxxx

With the following contents:

 
late_commands:
  custom: ["curtin", "in-target", "--", "sh", "-c", "/bin/echo -en 'Installed ' > /maas_hello_world"]

Then I release the machine and deploy the machine.

But after the deployment is done, there is no /maas_hello_world file,

what am I missing?

It is starting to work now.

  • It is not the machine ID, but the hostname (does not show up in the URL as the doc states).
  • The file does not work as stated, I need to add something else, not clear what. I added this content to the provided sample (which includes a lot of things) and now it works. Not sure if all the contents of the sample are required or just some.

just in case someone comes looking after this, I finally get something to work with this file:

#cloud-config
debconf_selections:
 maas: |
  {{for line in str(curtin_preseed).splitlines()}}
  {{line}}
  {{endfor}}
early_commands:
{{if third_party_drivers and driver}}
  {{py: key_string = ''.join(['\\x%x' % x for x in driver['key_binary']])}}
  {{if driver['key_binary'] and driver['repository'] and driver['package']}}
  driver_00_get_key: /bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg
  driver_01_add_key: ["apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
  {{endif}}
  {{if driver['repository']}}
  driver_02_add: ["add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
  {{endif}}
  {{if driver['package']}}
  driver_03_update_install: ["sh", "-c", "apt-get update --quiet && apt-get --assume-yes install {{driver['package']}}"]
  {{endif}}
  {{if driver['module']}}
  driver_04_load: ["sh", "-c", "depmod && modprobe {{driver['module']}} || echo 'Warning: Failed to load module: {{driver['module']}}'"]
  {{endif}}
{{else}}
  driver_00: ["sh", "-c", "echo third party drivers not installed or necessary."]
{{endif}}
write_files:
  # Create the vtkops user
  userconfig:
    path: /etc/cloud/cloud.cfg.d/99-opsuser.cfg
    content: |
      users:
        - name: opsuser
          sudo: ALL=(ALL) NOPASSWD:ALL
          shell: /bin/bash
          lock_passwd: true
          ssh_authorized_keys:
            - ssh-rsa .....
late_commands:
  maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
{{if third_party_drivers and driver}}
  {{if driver['key_binary'] and driver['repository'] and driver['package']}}
  driver_00_key_get: curtin in-target -- sh -c "/bin/echo -en '{{key_string}}' > /tmp/maas-{{driver['package']}}.gpg"
  driver_02_key_add: ["curtin", "in-target", "--", "apt-key", "add", "/tmp/maas-{{driver['package']}}.gpg"]
  {{endif}}
  {{if driver['repository']}}
  driver_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
  {{endif}}
  driver_04_update_install: ["curtin", "in-target", "--", "apt-get", "update", "--quiet"]
  {{if driver['package']}}
  driver_05_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "{{driver['package']}}"]
  {{endif}}
  driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
  driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
{{endif}}

Honestly I don’t know if I have to leave all those driver_00 to driver_07 I don’t know if they are a sample of what can be done, or the sample is a skeleton of what it is required to implement.

1 Like

By the way, I also noticed that by including the cloud-init users block without mentioning the default-user (see reference) the ubuntu user will not be created, but only our opsuser.

hi @rvallel, I’m glad it works.
The template of curtin_userdata_xxxx of my maas installation doesn’t have any of the driver_xx steps.
What version of maas are you using?

I am using the snap 2.8 distribution

can you paste your template?

I’m using 2.8 from snap. I have already seen the reason, I do not deploy Ubuntu. I use CentOS, where those driver steps do not come in the template.

anyway a small example of how I configure using ansible:

#cloud-config
debconf_selections:
 maas: |
  {{for line in str(curtin_preseed).splitlines()}}
  {{line}}
  {{endfor}}


swap:
  size: 0

late_commands:
  maas: [wget, '--no-proxy', '{{node_disable_pxe_url}}', '--post-data', '{{node_disable_pxe_data}}', '-O', '/dev/null']
  10_epel: ["curtin", "in-target", "--", "sh", "-c", "/usr/bin/dnf -y install epel-release"]
  20_ansible: ["curtin", "in-target", "--", "sh", "-c", "/usr/bin/dnf -y install postfix ansible python3-jmespath git"]
  40_clone: ["curtin", "in-target", "--", "sh", "-c", "git clone https://token@gitlab/ansible/ansible.git /tmp/ansible"]
  50_ansible_cloudinit: ["curtin", "in-target", "--", "sh", "-c", "ansible-playbook -vvvvv --connection=local --inventory 127.0.0.1, --limit 127.0.0.1 /tmp/ansible/my_playbook.yml -t cloudinit"]
  90_clear: ["curtin", "in-target", "--", "sh", "-c", "rm -rf /tmp/ansible"]

the question is that these are not “sample” files, because some of this lines are mandatory.

I am guessing the debconf_selections and also the disable_pxe

but I have no clue about the rest.

you have added those 10_ to 90_ right?

Exactly, if you look at the templates they contain the necessary steps. In ubuntu it is possible to install drivers. I guess if this variable third_party_drivers is enabled during commissioning when maas deploy the machine install the drivers.

I have also added the swap section, to diable the swap file create by default.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.