cloud-init does not create defined users

Bug #1562918 reported by Leander Janssen on 2016-03-28
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
High
Unassigned

Bug Description

When cloud-init tries to create the defined user a python error occurs:

# /var/log/cloud-init.log

Mar 28 17:27:25 ubuntu [CLOUDINIT] helpers.py[DEBUG]: Running config-users-groups using lock (<FileLock using file '/var/lib/cloud/instances/nocloud/sem/config_users_groups'>)
Mar 28 17:27:25 ubuntu [CLOUDINIT] util.py[DEBUG]: Running command ['groupadd', 'sysop'] with allowed return codes [0] (shell=False, capture=True)
Mar 28 17:27:25 ubuntu [CLOUDINIT] __init__.py[INFO]: Created new group sysop
Mar 28 17:27:25 ubuntu [CLOUDINIT] util.py[DEBUG]: Running command ['groupadd', 'ansible'] with allowed return codes [0] (shell=False, capture=True)
Mar 28 17:27:25 ubuntu [CLOUDINIT] __init__.py[INFO]: Created new group ansible
Mar 28 17:27:25 ubuntu [CLOUDINIT] handlers.py[DEBUG]: finish: init-network/config-users-groups: FAIL: running config-users-groups with frequency once-per-instance
Mar 28 17:27:25 ubuntu [CLOUDINIT] util.py[WARNING]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py'>) failed
Mar 28 17:27:25 ubuntu [CLOUDINIT] util.py[DEBUG]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py'>) failed#012Traceback (most recent call last):#012 File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 729, in _run_modules#012 freq=freq)#012 File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 70, in run#012 return self._runners.run(name, functor, args, freq, clear_on_fail)#012 File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 199, in run#012 results = functor(*args)#012 File "/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py", line 34, in handle#012 cloud.distro.create_user(user, **config)#012 File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 419, in create_user#012 self.add_user(name, **kwargs)#012 File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 373, in add_user#012 for group in kwargs.get('groups').split(","):#012AttributeError: 'NoneType' object has no attribute 'split'

#cloud-config
groups:
  - sysop
  - ansible

users:
  - name: sysop
    gecos: System Operator
    shell: /bin/bash
    lock-passwd: false
    sudo: ALL=(ALL) NOPASSWD:ALL
    passwd: $6$rounds=4096$y8sPi6ZhIVRN$bxASp.uEcBf3JjJvrYOZrU1hUHJrdlkdJCX9W0.fkNKi.i/qy6iTqmlcnr5s8VOwOomddbXIXVKkQ9C3wTzSr/

# lsb_release -rd
Description: Ubuntu Xenial Xerus (development branch)
Release: 16.04

# apt-cache policy cloud-init
cloud-init:
  Installed: 0.7.7~bzr1189-0ubuntu1
  Candidate: 0.7.7~bzr1189-0ubuntu1
  Version table:
 *** 0.7.7~bzr1189-0ubuntu1 500
        500 http://nl.archive.ubuntu.com/ubuntu xenial/main amd64 Packages
        500 http://nl.archive.ubuntu.com/ubuntu xenial/main i386 Packages
        100 /var/lib/dpkg/status

Related branches

Scott Moser (smoser) on 2016-03-30
Changed in cloud-init (Ubuntu):
status: New → Confirmed
importance: Undecided → High
Scott Moser (smoser) wrote :

Leander,
  Thanks for the bug report. Sorry for the regression.
I suspect that you can work around the issue by just putting your user into a group. Ie, you add 2 groups, but your user is not in either one of them.

We'll get this fixed.

Scott Moser (smoser) wrote :

Leander,
 I'd appreciate you giving the linked branch a test if you're up for it.
 I dont have time at the moment and probably wont until next week.

You can either build a deb with:
 ./packages/bddeb

or just apply the diff (copy in the new cloudinit/distros/__init__.py

Thanks.

I've applied the diff.
The defined users are now being created, but only when their primary group is created first using the groups statement.
The users are also correctly added to the specified additionals groups.

I've pasted my userdata below:

#cloud-config

groups:
  - ansible
  - sysop

users:
  - name: sysop
    gecos: "System Operator"
    primary-group: sysop
    groups: "sudo,adm"
    shell: /bin/bash
    lock-passwd: false
    passwd: <redacted>
  - name: ansible
    gecos: Ansible
    primary-group: ansible
    groups: sudo
    shell: /bin/bash

Download full text (3.9 KiB)

When I remove the groups: part I get the following errors in the /var/log/cloud-init.log:

Mar 31 22:35:45 test [CLOUDINIT] stages.py[DEBUG]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/
cloudinit/config/cc_users_groups.py'>) with frequency once-per-instance
Mar 31 22:35:45 test [CLOUDINIT] handlers.py[DEBUG]: start: init-network/config-users-groups: running config-users-groups with frequency once-per-instance
Mar 31 22:35:45 test [CLOUDINIT] util.py[DEBUG]: Writing to /var/lib/cloud/instances/nocloud/sem/config_users_groups - wb: [420] 24 bytes
Mar 31 22:35:45 test [CLOUDINIT] helpers.py[DEBUG]: Running config-users-groups using lock (<FileLock using file '/var/lib/cloud/instances/nocloud/sem/config_us
ers_groups'>)
Mar 31 22:35:45 test [CLOUDINIT] __init__.py[DEBUG]: Adding user ansible
Mar 31 22:35:45 test [CLOUDINIT] util.py[DEBUG]: Running hidden command to protect sensitive input/output logstring: ['useradd', 'ansible', '--shell', '/bin/bash', '--gid', 'ansible', '--comment', 'Ansible', '--groups', 'sudo', '-m']
Mar 31 22:35:45 test [CLOUDINIT] util.py[WARNING]: Failed to create user ansible
Mar 31 22:35:46 test [CLOUDINIT] util.py[DEBUG]: Failed to create user ansible#012Traceback (most recent call last):#012 File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 406, in add_user#012 util.subp(adduser_cmd, logstring=log_adduser_cmd)#012 File "/usr/lib/python3/dist-packages/cloudinit/util.py", line 1704, in subp#012 cmd=args)#012cloudinit.util.ProcessExecutionError: Unexpected error while running command.#012Command: ['useradd', 'ansible', '--shell', '/bin/bash', '--gid', 'ansible', '--comment', 'Ansible', '--groups', 'sudo', '-m']#012Exit code: 6#012Reason: -#012Stdout: ''#012Stderr: "useradd: group 'ansible' does not exist\n"
Mar 31 22:35:46 test [CLOUDINIT] handlers.py[DEBUG]: finish: init-network/config-users-groups: FAIL: running config-users-groups with frequency once-per-instance
Mar 31 22:35:46 test [CLOUDINIT] util.py[WARNING]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py'>) failed
Mar 31 22:35:46 test [CLOUDINIT] util.py[DEBUG]: Running module users-groups (<module 'cloudinit.config.cc_users_groups' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py'>) failed#012Traceback (most recent call last):#012 File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 735, in _run_modules#012 freq=freq)#012 File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 70, in run#012 return self._runners.run(name, functor, args, freq, clear_on_fail)#012 File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 199, in run#012 results = functor(*args)#012 File "/usr/lib/python3/dist-packages/cloudinit/config/cc_users_groups.py", line 34, in handle#012 cloud.distro.create_user(user, **config)#012 File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", line 419, in create_user#012 self.add_user(name, **kwargs)#012 File "/usr/lib/python3/dist-packages/cloudinit/distros/__init__.py", li...

Read more...

Please ignore my last comment (#4).

When specifying an explicit primary-group it should of course already exist, before useradd can create the user.
When removing the primary-group statement from the user definition the user is created just fine (including it's primary group with the same name as the user).

For me this has fixed the issue I've reported.

Launchpad Janitor (janitor) wrote :

This bug was fixed in the package cloud-init - 0.7.7~bzr1200-0ubuntu1

---------------
cloud-init (0.7.7~bzr1200-0ubuntu1) xenial; urgency=medium

  * New upstream snapshot.
    - fix adding of users when no group is specified (LP: #1562918)
    - fix write_files with compressed content (LP: #1565638)
    - systemd: do not specify After of obsolete syslog.target (LP: #1536964)
    - chef: fix chef installation from gems (LP: #1553345)
    - disk_setup: correctly send force to mkfs on block devices (LP: #1548772)
    - locale: list unsupported environment settings in warning (LP: #1558069)
    - fix NoCloud and other datasources if no datasource config (LP: #1514407)

 -- Scott Moser <email address hidden> Wed, 06 Apr 2016 13:07:27 -0400

Changed in cloud-init (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers