virt-lightning / freebsd-cloud-images

Shell script to build the FreeBSD cloud images
31 stars 12 forks source link

bare minimum cloud init #5

Closed till closed 5 months ago

till commented 2 years ago

Hey ๐Ÿ‘‹๐Ÿผ !

Thanks for publishing these images, I am trying to use the 13.0 one and got excited when I saw that you had cloud-init included. :D

Few questions, from scrolling through the repo.

  1. Is there a default user?
  2. Do you know if the ssh key injection via the provider works?
  3. Do you have a bare minimum cloud-config that creates an account and allows login via ssh key?

Here is the cloud-config I used:

#cloud-config
users:
  - name: till
    sudo: true
    lock_passwd: true
    ssh_authorized_keys:
      - my-public-key

It sorta work, but I can't login (it'll ask me for password). I scrolled through the log, I noticed it discovered my dhcp settings and created an account (even though I can't login).

...
/usr/local/bin/cloud-init startingCloud-init v. 21.2 running 'init-local' at Sun, 25 Sep 2022 14:34:15 +0000. Up 3.7391374111175537 seconds.
2022-09-25 14:34:15,895 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceOpenStack.DataSourceOpenStackLocal'> failed
...
/usr/local/bin/cloud-init startingCloud-init v. 21.2 running 'init' at Sun, 25 Sep 2022 14:34:23 +0000. Up 10.971212387084961 seconds.
ci-info: ++++++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++++++
ci-info: +--------+------+-----------------+------------+-------+-------------------+
ci-info: | Device |  Up  |     Address     |    Mask    | Scope |     Hw-Address    |
ci-info: +--------+------+-----------------+------------+-------+-------------------+
ci-info: |  lo0   | True |    127.0.0.1    | 0xff000000 |   .   |         .         |
ci-info: |  lo0   | True |     ::1/128     |     .      |   .   |         .         |
ci-info: |  lo0   | True |  fe80::1%lo0/64 |     .      |  0x2  |         .         |
ci-info: | vtnet0 | True | ip   | 0xffffff00 |   .   | fa:16:3e:12:9c:ea |
ci-info: +--------+------+-----------------+------------+-------+-------------------+
ci-info: 
lo0: link state changed to DOWN
lo0: link state changed to UP
2022-09-25 14:34:28,100 - util.py[WARNING]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/local/lib/python3.7/site-packages/cloud_init-21.2-py3.7.egg/cloudinit/config/cc_users_groups.py'>) failed
...
/usr/local/bin/cloud-init startingCloud-init v. 21.2 running 'modules:final' at Sun, 25 Sep 2022 14:34:29 +0000. Up 17.358665704727173 seconds.
ci-info: no authorized SSH keys fingerprints found for user till.
ci-info: no authorized SSH keys fingerprints found for user till.
till commented 2 years ago

Found an example in one of your other repositories ๐Ÿ‘๐Ÿผ : https://github.com/virt-lightning/cloud-init-bsd-testing/blob/master/user_data

I think my key was not in "expected" format:

users:
  - default
  - name: till
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh_authorized_keys:
-     - ssh-rsa hash==
+     - ssh-rsa hash== till@local

And from there, I also answered my first question: I found it by including default in the list of users (which I guess is another cloud-init oddity) that it would create a freebsd user and showed a comment/description from OpenStack.

Most openstack images create a user when a key is injected, so for example ubuntu or centos. Not entirely sure what Debian does, I haven't booted that in a long time.

Would you be open to changing that? I can probably work up a PR if you let me know where.

till commented 2 years ago

Most openstack images create a user when a key is injected, so for example ubuntu or centos. Not entirely sure what Debian does, I haven't booted that in a long time.

Would you be open to changing that? I can probably work up a PR if you let me know where.

Just found /etc/cloud/cloud.cfg and it already does this, but I ruined it by trying cloud-config first. :)

till commented 2 years ago

Could we add this to the readme? Maybe without the Ansible.

- name: Export the images
      command: 'qemu-img convert -f raw -O qcow2 -c images/basehost/builder/final.raw /var/lib/virt-lightning/pool/upstream/{{ final_name }}_exp.qcow2'
      args:
        creates: '/var/lib/virt-lightning/pool/upstream/{{ final_name }}_exp.qcow2
goneri commented 6 months ago

Sorry for being slow on this. This is a good idea. Could you open up a PR for that?

till commented 5 months ago

You mean the bit about building an image?

goneri commented 5 months ago

Never mind, I misunderstood your previous comment. We don't really need to mention this step since the images are already compressed (the -c).