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

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

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.

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…

:-/

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…

:-/

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.

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

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'

@andreserl where is the curtin documentation that covers the userconfig object you’re using in the curtin_preseed file there? I need to create an additional default user (along with the usual login user) and I need to add a public key to that account and I need to add a sudo entry for said user. Given those and a few other things I need to do, I’d really like to view the documentation so I can know all my options. Unfortunately, my searched in the curtin documentation have been futile.

I found https://curtin.readthedocs.io/en/latest/topics/config.html – is that the best resource?

@snafuxnj The curtin configuration stanza I’m using is not ‘userconfig’, it is write_files. The ‘userconfig’ word is just a descriptive name/word that describes the section that write_files will write on the target.

The content of the file that write_files will write, is cloud-init user data. In other words, what my code snippet does is to write cloud-init configuration into the installed filesystem (under /etc/cloud/cloud.cfg.d/00-user.cfg), which is then read by cloud-init on first boot post-deployment.

So write_files is explained in the curtin configuration: https://curtin.readthedocs.io/en/latest/topics/config.html

The content is based from https://cloudinit.readthedocs.io/en/latest/topics/examples.html (see Default user creation).

1 Like

I wanted to post my progress for posterity sake:

OK, so I did that and I’m liking how this works.

I added the user to the /etc/maas/preseeds/curtin_userdata_custom file so that the configuration we’re adding applies to the custom images we’re using vs everything.

At first it failed. Completely. I checked the cloud-init logs on the ephemeral test host and found no references to the stuff I placed in my config. In fact, the file I told it to write out did not exist on the test machine. I was very confused.

I decided to run a linter on the altered curtin_userdata_custom file and I found and fixed a couple of mildly innocuous things, so I thought. The only thing I really ignored was the line-length warnings. Saved and ran another test.

Bang! Progress. I wasn’t completely out of the woods yet. I needed to polish. A few things I took away for lessons learned:

  • Make sure the file you intended to write out on the finally-booted ephemeral host is there IE /etc/cloud/cloud.cfg.d/<file>. If it’s not, something is likely wrong with your stuff you changed in the preseeds config template(s).
  • If the finally-booted ephemeral machine is writing the config but you’re not seeing the user(s) you intended to add, check the cloud-init logs IE /var/log/cloud*log and search for username. Pay attention to errors for useradd. My initial user addition failed because I specified an selinux group on an image where selinux was disabled. The useradd failed because of that.