Hello there,
This is how I download an ubuntu cloud image:
wget -c https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img -O ~/noble-server-cloudimg-amd64.img
virt-customize -a noble-server-cloudimg-amd64.img \
--timezone Asia/Tehran \
--root-password password:q \
--run-command 'sed -i "s/^disable_root.*/disable_root: false/" /etc/cloud/cloud.cfg' \
--run-command 'grep -q "^ssh_pwauth:" /etc/cloud/cloud.cfg && sed -i "s/^ssh_pwauth:.*/ssh_pwauth: true/" /etc/cloud/cloud.cfg || echo "ssh_pwauth: true" >> /etc/cloud/cloud.cfg' \
--run-command 'printf "PasswordAuthentication yes\nPermitRootLogin yes\n" > /etc/ssh/sshd_config.d/99-allow-root.conf' \
--run-command "sed -e 's/^[# ]*PasswordAuthentication.*/PasswordAuthentication yes/g' -i /etc/ssh/sshd_config || true" \
--run-command "sed -e 's/^[# ]*PermitRootLogin.*/PermitRootLogin yes/g' -i /etc/ssh/sshd_config || true" \
--run-command 'systemctl enable ssh || systemctl enable sshd' \
--run-command 'systemctl disable systemd-networkd-wait-online.service'
openstack image create --file ~/noble-server-cloudimg-amd64.img --disk-format qcow2 --container-format bare --public --property os_distro=ubuntu --property hw_qemu_guest_agent=yes "Ubuntu 24" || true
rm -f noble-server-cloudimg-amd64.img
cat <<EOF > /root/userdata.txt
#cloud-config
chpasswd:
list: |
root:q
expire: False
ssh_pwauth: True
cmd:
- systemctl disable systemd-networkd-wait-online.service
EOF
openstack server create --image "Ubuntu 24" --flavor first --network public_network --config-drive True ahmad --password 'ahmad'
This is how I create image.
I'm going to find a way if possible, to set the admin password during the "server create".
Currently the root login is only possible with password "q". The "ahmad" is not working.
I know I can change it via user-data file (I intentionally added there but not using it), but the question is can I set the password during the server create?
I tried to use "virt-customize --install qemu-guest-agent", but the virt-customize has no network, so no installation.
I also know I can do this:
1. create server
2. do whatever I want (install guest agent, etc)
3. create snapshot
4. create server from that snapshot
But the issue is it's not automatic (I should manually login to do the modification) and its size is much more than the cloud image. Like, from 500 megabytes which is cloud image, goes around 3 gigabytes which is the snapshot.
Any ways to reach what I'm looking for?
Or even any better ways to do that?
Regards,
Ahmad