Simple question, hard to find the answer... How to change default user of deployed Machine?


#1

Guys,

This sounds like a simple question but I can’t find a straight and simple answer to it!

When deploying Machines via MaaS, the “default_user” create by cloud-init (I believe), is “ubuntu”.

I don’t want it!

In an OpenStack / Cloud environment, I have the following block in my Heat templates for my “OS::Nova::Server”:

user_data: |
  #cloud-config
  system_info:
    default_user:
      name: "tcmc"
  chpasswd:
    list: |
      root:tcmc
      tcmc:tcmc
    expire: False

So, how can I do this in MaaS, in a wah that all Machines will get it automatically?

I tried many pressed stuff, none worked.

No idea about how to do this simple thing on MaaS globally.

Thanks!
Thiago


#2

Looking at the cloud-unit/user-data section here, possibly you can set the same user-data you are setting with heat via the the maas cli.

Disclaimer: Never actually tried changing the default user, but this seems reasonable.


#3

I was reading that doc yesterday… I tried to create a new file called “curtin_userdata_ubuntu” with my #cloud-init block, then, the deployments started to fail.

I also tried to write a file, /etc/cloud/cloud.cfg.d/default_user.cfg but that file never appeared…

I tried to change the default user for about 5~6 hours yesterday without success…

:-/


#4

I was reading the following post:

https://gist.github.com/smoser/e917b2873aff767cb454cb0513a564a4

…and tried to write_files into my cloud init cfg subdir… Didn’t worked…

BTW, it would be AWESOME to have this implemented: https://bugs.launchpad.net/maas/+bug/1734391

Then, I found another example, here:

https://code.launchpad.net/~bladernr/maas-cert-server/mcs-add-ocp-curtin-userdata/+merge/266964

…at line 99, tried, didn’t worked either!

So, it’s near to “impossible” to do a simple thing, change the default user of a deployed Machine with MaaS.

I gave up for now.

I’ll just create another user for me with Ansible and move on…

:-/


#5

I guess that I’m also facing the following bug:

https://bugs.launchpad.net/curtin/+bug/1734274

While I can’t see that specific error:

curtin: Installation failed with exception: 'NoneType' object has no attribute 'keys'

My deployment also fails if I try this:

File `/etc/maas/preseeds/curtin_userdata_ubuntu that contains:

#cloud-config
system_info:
  default_user:
    name: "tcmc"

Still don’t know how to change the default_user… It’s kinda of, embarrassing, to not be able to do this.


#6

I do this from the CLI.

lloyd@maas:~$ cat cloud-config-common
#cloud-config
users:
  - name: lloyd
    gecos: Lloyd Parkes
    groups: adm, sudo
    sudo: ALL=(ALL) NOPASSWD:ALL
    shell: /bin/bash
    ssh-authorized-keys:
      - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCySWOEbC1w3TdImewA1eBLiyE2jM/Tn6dCrGhNmNTQNNITgg0Huy4cLDpuUASUqWEF7YVWkEseW6Kz01Y5KxRfiQDRYBxql7nsdEp4YuHmaYOBoAcjm/p7FOVPcAHZ0S1qRVNvL+zANvJHFINUoVblu3+WN/87NVPdEFtNa/QeX9N7RFbfw8NA85cFbgjFnVXX3ipJsduJYrspsCYJfxqoGNKswv79Zdi5SGkJQNn4bHRimtaF8MPtEOy0WhjKCcaf3DSbGtTMmEhcS6M/zKUlwGnyiwgRysuF+DeiyEedXtNwDJqL9kXP4w9KPQtnjlICwAG178c9MRaYzHA2gReX lloyd@ansible
lloyd@maas:~$ maas cli machine deploy ces6hn user_data=$(base64 -w0 -i cloud-config-common) distro_series=bionic

#7

You can add a section like the following to /etc/maas/preseeds/curtin_userdata

write_files:
  # Create cloud-init config that configures the 'root' user as the
  # default user instead of 'centos'.
  # Additionally, enables password authentication for this user.
  userconfig:
    path: /etc/cloud/cloud.cfg.d/00-user.cfg
    content: |
     ssh_pwauth: yes
     disable_root: false
     system_info:
       default_user:
         name: root
         lock_passwd: false
         plain_text_passwd: 'test'