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 (

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

 - default

[___skipped some lines ___]

    name: centos
    lock_passwd: true
    gecos: Cloud User
    groups: [adm, systemd-journal]
    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
    shell: /bin/bash
  distro: rhel
    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:

    path: /etc/cloud/cloud.cfg
    permissions: '0400'
    content: |

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


With the following contents:

  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:

 maas: |
  {{for line in str(curtin_preseed).splitlines()}}
{{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"]
  {{if driver['repository']}}
  driver_02_add: ["add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
  {{if driver['package']}}
  driver_03_update_install: ["sh", "-c", "apt-get update --quiet && apt-get --assume-yes install {{driver['package']}}"]
  {{if driver['module']}}
  driver_04_load: ["sh", "-c", "depmod && modprobe {{driver['module']}} || echo 'Warning: Failed to load module: {{driver['module']}}'"]
  driver_00: ["sh", "-c", "echo third party drivers not installed or necessary."]
  # Create the vtkops user
    path: /etc/cloud/cloud.cfg.d/99-opsuser.cfg
    content: |
        - name: opsuser
          sudo: ALL=(ALL) NOPASSWD:ALL
          shell: /bin/bash
          lock_passwd: true
            - ssh-rsa .....
  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"]
  {{if driver['repository']}}
  driver_03_add: ["curtin", "in-target", "--", "add-apt-repository", "-y", "deb {{driver['repository']}} {{node.get_distro_series()}} main"]
  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']}}"]
  driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
  driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]

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:

 maas: |
  {{for line in str(curtin_preseed).splitlines()}}

  size: 0

  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, --limit /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.