3

I'm trying to create a profile to automate the creation of a container, but I'm having trouble with cloud-init. For some reason the password is not being set for the user and is also not being added as a sudoer. Here is the YAML:

config:
  boot.autostart: "false"
  limits.cpu: "2"
  limits.memory: "4GB"
  user.user-data: |
    #cloud-config
    users:
      - name: matheus
        gecos: Matheus Saraiva da Silva
        lock_password: false
        plain_text_passwd: tyy7854
        ssh-authorized-keys:
          - ssh-rsa myrsa
    package_update: true
    package_upgrade: true
    package_reboot_if_required: true
    snap:
      commands:
        00: snap install juju --classic
        01: snap install charmcraft --classic
        02: snap install node --classic
    apt:
      preserve_source_list: true
    packages:
      - gcc
      - podman
    runcmd:
      - usermod, -aG, sudo matheus
      - [su, matheus, -c, "wget https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb -P /home/matheus/Downloads"]
      - [su, matheus, -c, "sudo dpkg -i /home/matheus/minikube_latest_amd64.deb"]
      - [su, matheus, -c, "git config --global user.name matheusssilva"]
      - [su, matheus, -c, "git config --global user.email [email protected]"]

description: TaskStack enviroment lxd profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: TaskStack
used_by: []

When I try to do something with sudo, the password that is in the configuration file does not work. So I am obliged to change the user's password using the root user #passwd matheus. Is it a bug?

1 Answer 1

1

You'll need to add your user to the sudo group, additionally you are using an invalid key lock_password which should be lock_passwd. If you check /var/log/cloud-init.log you'll note the following log:

subp.py[DEBUG]: Running command ['passwd', '-l', 'matheus'] with allowed return codes [0] (shell=False, capture=True)

which is being ran because the default is to disable user passwords

Run cloud-init schema --system to verify that the system cloud-config userdata is valid.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .