AlmaLinux / cloud-images

Packer templates and other tools for building AlmaLinux images for various cloud platforms.
MIT License
147 stars 46 forks source link

chpasswd with cloud-config on AWS fails #83

Closed StanvanHoorn closed 1 year ago

StanvanHoorn commented 2 years ago

When deploying an AWS instance with the AlmaLinux 8 image, chpasswd doesn't seem to work.

Example config:

chpasswd:
  list: |
    root:${root_hash}

Error message:

2022-04-21 11:04:11,620 - util.py[DEBUG]: Failed to set hashed passwords with chpasswd for ['root']
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py", line 206, in handle
    chpasswd(cloud.distro, hashed_ch_in, hashed=True)
  File "/usr/lib/python3.6/site-packages/cloudinit/config/cc_set_passwords.py", line 252, in chpasswd
    subp.subp(cmd, plist_in)
  File "/usr/lib/python3.6/site-packages/cloudinit/subp.py", line 295, in subp
    cmd=args)
cloudinit.subp.ProcessExecutionError: Unexpected error while running command.
Command: ['chpasswd', '-e']
Exit code: 1
Reason: -
Stdout:
Stderr: chpasswd: cannot open /etc/passwd

Alternatives like Rocky don't seem to have this issue

LKHN commented 2 years ago

Hey @StanvanHoorn I cannot reproduce any issues. Everything works as expected. The list key accepts two types of the value, multiline string and list.

The use of the multiline string for this field is deprecated and will result in an error in a future version of cloud-init. I've tested both versions

multiline string:

#cloud-config

chpasswd:
  list: |
    root:$hash

list:

#cloud-config

chpasswd:
  list:
    - root:$hash