karmab / kcli

Management tool for virtualization and kubernetes platforms
https://kcli.readthedocs.io/en/latest/
Apache License 2.0
515 stars 140 forks source link

centos8stream passwd set falied #723

Closed BurlyLuo closed 1 month ago

BurlyLuo commented 1 month ago
# 2. centos8stream
kcli create vm -i centos8stream -P memory=4096 -P disks=[50] -P rootpassword=hive -P nets="[{'name':'brnet','ip':'192.168.2.96','netmask':'24','gateway':'192.168.2.1'},{'name':'vppdpdk5'},{'name':'vppdpdk8'},{'name':'vppdpdk9'}]" -P cpupinning=['{"vcpus": "0", "hostcpus": "0"}','{"vcpus": "1", "hostcpus": "1"}','{"vcpus": "2", "hostcpus": "2"}','{"vcpus": 3, "hostcpus": 3}'] -P numcpus=4 -P cmds='[rm -rf /etc/yum.repos.d/* && curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo && yum -y install net-tools pciutils wget lrzsz && wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]' vm

[root@rowan> virtkcli]# kcli  list vms
+---------------------+--------+--------------+---------------+-------+---------------+
|         Name        | Status |      Ip      |     Source    |  Plan |    Profile    |
+---------------------+--------+--------------+---------------+-------+---------------+
| IPv4_K8S_1_28_2_50G |  down  |              |               |       |               |
|          vm         |   up   | 192.168.2.96 | centos8stream | kvirt | centos8stream |
|         vpp1        |  down  |              |               |       |               |
+---------------------+--------+--------------+---------------+-------+---------------+
[root@rowan> virtkcli]# virsh console vm
Connected to domain 'vm'
Escape character is ^] (Ctrl + ])
[FAILED] Failed to start Network Manager Wait Online.
See 'systemctl status NetworkManager-wait-online.service' for details.
         Starting Initial cloud-init job (metadata service crawler)...
[   69.302554] cloud-init[853]: Cloud-init v. 23.4-7.el8.3 running 'init' at Wed, 25 Sep 2024 03:46:07 +0000. Up 69.14 seconds.
[   69.306996] cloud-init[853]: ci-info: ++++++++++++++++++++++++++++++++++++++Net device info++++++++++++++++++++++++++++++++++++++
[   69.310818] cloud-init[853]: ci-info: +--------+------+----------------------------+---------------+--------+-------------------+
[   69.314464] cloud-init[853]: ci-info: | Device |  Up  |          Address           |      Mask     | Scope  |     Hw-Address    |
[   69.318497] cloud-init[853]: ci-info: +--------+------+----------------------------+---------------+--------+-------------------+
[   69.322226] cloud-init[853]: ci-info: |  eth0  | True |        192.168.2.96        | 255.255.255.0 | global | 52:54:00:26:5e:3f |
[   69.325659] cloud-init[853]: ci-info: |  eth0  | True | fe80::5054:ff:fe26:5e3f/64 |       .       |  link  | 52:54:00:26:5e:3f |
[   69.329192] cloud-init[853]: ci-info: |  eth1  | True | fe80::5054:ff:fe3a:fe77/64 |       .       |  link  | 52:54:00:3a:fe:77 |
[   69.332963] cloud-init[853]: ci-info: |  eth2  | True | fe80::5054:ff:fe44:7d1d/64 |       .       |  link  | 52:54:00:44:7d:1d |
[   69.336666] cloud-init[853]: ci-info: |  eth3  | True | fe80::5054:ff:fe85:2094/64 |       .       |  link  | 52:54:00:85:20:94 |
[   69.340689] cloud-init[853]: ci-info: |   lo   | True |         127.0.0.1          |   255.0.0.0   |  host  |         .         |
[   69.344332] cloud-init[853]: ci-info: |   lo   | True |          ::1/128           |       .       |  host  |         .         |
[   69.348046] cloud-init[853]: ci-info: +--------+------+----------------------------+---------------+--------+-------------------+
[   69.351617] cloud-init[853]: ci-info: +++++++++++++++++++++++++++++Route IPv4 info+++++++++++++++++++++++++++++
[   69.354706] cloud-init[853]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+
[   69.357833] cloud-init[853]: ci-info: | Route | Destination |   Gateway   |    Genmask    | Interface | Flags |
[   69.361039] cloud-init[853]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+
[   69.364184] cloud-init[853]: ci-info: |   0   |   0.0.0.0   | 192.168.2.1 |    0.0.0.0    |    eth0   |   UG  |
[   69.367437] cloud-init[853]: ci-info: |   1   | 192.168.2.0 |   0.0.0.0   | 255.255.255.0 |    eth0   |   U   |
[   69.370924] cloud-init[853]: ci-info: +-------+-------------+-------------+---------------+-----------+-------+
[   69.373493] cloud-init[853]: ci-info: +++++++++++++++++++Route IPv6 info+++++++++++++++++++
[   69.375864] cloud-init[853]: ci-info: +-------+-------------+---------+-----------+-------+
[   69.378921] cloud-init[853]: ci-info: | Route | Destination | Gateway | Interface | Flags |
[   69.381606] cloud-init[853]: ci-info: +-------+-------------+---------+-----------+-------+
[   69.384321] cloud-init[853]: ci-info: |   1   |  fe80::/64  |    ::   |    eth0   |   U   |
[   69.386626] cloud-init[853]: ci-info: |   2   |  fe80::/64  |    ::   |    eth1   |   U   |
[   69.389358] cloud-init[853]: ci-info: |   3   |  fe80::/64  |    ::   |    eth2   |   U   |
[   69.391741] cloud-init[853]: ci-info: |   4   |  fe80::/64  |    ::   |    eth3   |   U   |
[   69.394116] cloud-init[853]: ci-info: |   6   |    local    |    ::   |    eth0   |   U   |
[   69.396490] cloud-init[853]: ci-info: |   7   |    local    |    ::   |    eth1   |   U   |
[   69.398918] cloud-init[853]: ci-info: |   8   |    local    |    ::   |    eth2   |   U   |
[   69.401263] cloud-init[853]: ci-info: |   9   |    local    |    ::   |    eth3   |   U   |
[   69.403924] cloud-init[853]: ci-info: |   10  |  multicast  |    ::   |    eth0   |   U   |
[   69.406466] cloud-init[853]: ci-info: |   11  |  multicast  |    ::   |    eth1   |   U   |
[   69.408843] cloud-init[853]: ci-info: |   12  |  multicast  |    ::   |    eth2   |   U   |
[   69.411211] cloud-init[853]: ci-info: |   13  |  multicast  |    ::   |    eth3   |   U   |
[   69.413764] cloud-init[853]: ci-info: +-------+-------------+---------+-----------+-------+
[   69.415866] cloud-init[853]: 2024-09-25 03:46:07,749 - schema.py[WARNING]: Invalid cloud-config provided: Please run 'sudo cloud-init schema --system' to see the schema errors.
[   70.254998] cloud-init[853]: Generating public/private rsa key pair.
[   70.257117] cloud-init[853]: Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
[   70.259681] cloud-init[853]: Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
[   70.262493] cloud-init[853]: The key fingerprint is:
[   70.264614] cloud-init[853]: SHA256:wfDMDqe4wdQpFIzFGB9NKX97p09PE96N3pIF6YooqD0 root@vm
[   70.267460] cloud-init[853]: The key's randomart image is:
[   70.269677] cloud-init[853]: +---[RSA 3072]----+
[   70.271471] cloud-init[853]: |  .B=+o.         |
[   70.273254] cloud-init[853]: |  oo+ooB         |
[   70.275213] cloud-init[853]: |    +o+ B      . |
[   70.277156] cloud-init[853]: |   o o.=..    o  |
[   70.279027] cloud-init[853]: |    + ..S.   ... |
[   70.281093] cloud-init[853]: |     o  . . ...+o|
[   70.283041] cloud-init[853]: |    ..   o +..=oo|
[   70.285114] cloud-init[853]: |   .E . . o..+oo |
[   70.287079] cloud-init[853]: |  .... .   .. o..|
[   70.288533] cloud-init[853]: +----[SHA256]-----+
[   70.290131] cloud-init[853]: Generating public/private ecdsa key pair.
[   70.291772] cloud-init[853]: Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
[   70.294311] cloud-init[853]: Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
[   70.296776] cloud-init[853]: The key fingerprint is:
[   70.298576] cloud-init[853]: SHA256:roAebkkWtH27a6Xy4TQ8iCpD2w/r9/+3T0zPbngmF/U root@vm
[   70.300816] cloud-init[853]: The key's randomart image is:
[   70.302956] cloud-init[853]: +---[ECDSA 256]---+
[   70.304580] cloud-init[853]: |                 |
[   70.306243] cloud-init[853]: |  .              |
[   70.307749] cloud-init[853]: | . o             |
[   70.309405] cloud-init[853]: |  o . .         .|
[   70.311008] cloud-init[853]: |   . . .S      .o|
[   70.312444] cloud-init[853]: | .oo o...     ooE|
[   70.314071] cloud-init[853]: |.o*oo *+.      ++|
[   70.315615] cloud-init[853]: |o=oo+=+=     .+.=|
[   70.316907] cloud-init[853]: |oo+oo=*o......oB.|
[   70.318431] cloud-init[853]: +----[SHA256]-----+
[   70.319745] cloud-init[853]: Generating public/private ed25519 key pair.
[   70.321769] cloud-init[853]: Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.
[   70.324355] cloud-init[853]: Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.
[   70.326960] cloud-init[853]: The key fingerprint is:
[   70.328476] cloud-init[853]: SHA256:E6jDLQ5XwX0cPEr+9FhbVQzigiQJjdCVZQT3qIgRC4k root@vm
[   70.330976] cloud-init[853]: The key's randomart image is:
[   70.332697] cloud-init[853]: +--[ED25519 256]--+
[   70.333994] cloud-init[853]: |o.oo.*=B*o... .oo|
[   70.335605] cloud-init[853]: |E. oo =Bo+=. .  o|
[  OK  ] Started Initial cloud-init job (metadata service crawler).
[   70.337251] cloud-init[853]: |  o   oo+oo..  . |
[  OK  ] Reached target Network is Online.
[   70.340631] cloud-init[853]: |   + = .o.... .  |
[   70.343377]          cloud-init[853]: Starting Crash recovery kernel arming...|  o B o So + o   |

[   70.346494] cloud-init[853]: |   + o   .o o    |
[   70.348345] cloud-init[853]: |    .            |
[   70.350579] cloud-init[853]: |                 |
[   70.352484] cloud-init[853]: |                 |
[   70.357303] cloud-init[853]: +----[SHA256]-----+
         Starting Notify NFS peers of a restart...
         Starting System Logging Service...
[  OK  ] Reached target Cloud-config availability.
         Starting Apply the settings specified in cloud-config...
         Starting OpenSSH server daemon...
[  OK  ] Started OpenSSH server daemon.
[  OK  ] Started Notify NFS peers of a restart.
[  OK  ] Started System Logging Service.
[   70.829061] cloud-init[1212]: Cloud-init v. 23.4-7.el8.3 running 'modules:config' at Wed, 25 Sep 2024 03:46:09 +0000. Up 70.72 seconds.
[  OK  ] Started Apply the settings specified in cloud-config.
         Starting Permit User Sessions...
         Starting Execute cloud user/final scripts...
[  OK  ] Started Permit User Sessions.
[  OK  ] Started Command Scheduler.
[  OK  ] Started Getty on tty1.
[  OK  ] Started Serial Getty on ttyS0.
[  OK  ] Reached target Login Prompts.
[  OK  ] Reached target Multi-User System.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Started Update UTMP about System Runlevel Changes.

CentOS Stream 8
Kernel 4.18.0-553.6.1.el8.x86_64 on an x86_64

Activate the web console with: systemctl enable --now cockpit.socket

vm login: root
Password: 
Login incorrect

vm login: root
Password: 
Login incorrect

vm login: login: timed out after 60 second
CentOS Stream 8
Kernel 4.18.0-553.6.1.el8.x86_64 on an x86_64

Activate the web console with: systemctl enable --now cockpit.socket

vm login: 

after set the passwd: 
    6  ssh 127.0.0.1
    7  vi /etc/ssh/sshd_config 
    8  passwd 
    9  ssh 127.0.0.1
karmab commented 1 month ago

was not able to reproduce the error, root password is properly injected in my testing

BurlyLuo commented 1 month ago
[root@vm ~]# ps -ef | grep yum
root        1710    1708  0 04:03 ?        00:00:00 /usr/libexec/platform-python /usr/bin/yum -y install qemu-guest-agent
root        4860    4813  0 04:06 pts/1    00:00:00 grep --color=auto yum
[root@vm ~]# 
[root@vm ~]# 
[root@vm ~]# 
[root@vm ~]# 
[root@vm ~]# kill -9 1710
[root@vm ~]# /usr/libexec/platform-python /usr/bin/yum -y install qemu-guest-agent
Last metadata expiration check: 0:00:01 ago on 2024年09月30日 星期一 04时07分23秒.
Package qemu-guest-agent-15:6.2.0-49.module_el8+991+097e156d.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@vm ~]# ps -ef | grep yum
root       13400    4813  0 04:07 pts/1    00:00:00 grep --color=auto yum
[root@vm ~]# 

[root@vm ~]# /usr/libexec/platform-python /usr/bin/yum -y install qemu-guest-agent block! From the above logs. we can see that if kill the /usr/libexec/platform-python /usr/bin/yum -y install qemu-guest-agent process. the cmds can be execed as expected. [cmds='[rm -rf /etc/yum.repos.d/* && pkill yum ; curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo ; pkill yum && yum -y install net-tools pciutils wget lrzsz ; wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]]

kcli create vm -i centos8stream -P memory=4096 -P disks=[50] -P rootpassword=hive -P nets="[{'name':'brnet','ip':'192.168.2.96','netmask':'24','gateway':'192.168.2.1'},{'name':'vppdpdk5'},{'name':'vppdpdk8'},{'name':'vppdpdk9'}]" -P cpupinning=['{"vcpus": "0", "hostcpus": "0"}','{"vcpus": "1", "hostcpus": "1"}','{"vcpus": "2", "hostcpus": "2"}','{"vcpus": 3, "hostcpus": 3}'] -P numcpus=4 -P cmds='[rm -rf /etc/yum.repos.d/* && pkill yum ; curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo ; pkill yum && yum -y install net-tools pciutils wget lrzsz ; wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]' vm
karmab commented 1 month ago

The issue is probably that your network lacks internet connectivity, causing the qemu-guest-agent install to fail. This package is needed in order to properly report the ip for bridged networks, but in commit https://github.com/karmab/kcli/commit/a8c64f4f2714daf31a21fd4d41f5d25afdf0c0b4 , I've introduced the variable guestagent so that you can disable this behaviour.

BurlyLuo commented 1 month ago

The issue is probably that your network lacks internet connectivity, causing the qemu-guest-agent install to fail. This package is needed in order to properly report the ip for bridged networks, but in commit a8c64f4 , I've introduced the variable guestagent so that you can disable this behaviour.

Okay.

[[ kcli create vm -i centos8stream -P memory=4096 -P disks=[50] -P rootpassword=hive -P guestagent=False -P nets="[{'name':'brnet','ip':'192.168.2.96','netmask':'24','gateway':'192.168.2.1'},{'name':'vppdpdk5'},{'name':'vppdpdk8'},{'name':'vppdpdk9'}]" -P cpupinning=['{"vcpus": "0", "hostcpus": "0"}','{"vcpus": "1", "hostcpus": "1"}','{"vcpus": "2", "hostcpus": "2"}','{"vcpus": 3, "hostcpus": 3}'] -P numcpus=4 -P cmds='[rm -rf /etc/yum.repos.d/* ; curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo ; yum -y install net-tools pciutils wget lrzsz ; wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth]' vm ]]

-P guestagent=False

[root@vm ~]# find / -name runcmd
/var/lib/cloud/instances/vm/scripts/runcmd
[root@vm ~]# cat /var/lib/cloud/instances/vm/scripts/runcmd
#!/bin/sh
echo root:hive | chpasswd
rm -rf /etc/yum.repos.d/* ; curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo ; yum -y install net-tools pciutils wget lrzsz ; wget http://192.168.2.100/kvm/tools/lseth -P /usr/bin/ && chmod +x /usr/bin/lseth
sed -i 's/.*PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd
[root@vm ~]#