Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user module with option local fails on Ubuntu #32199

Closed
rmfrankch opened this issue Oct 26, 2017 · 6 comments · Fixed by #32262
Closed

user module with option local fails on Ubuntu #32199

rmfrankch opened this issue Oct 26, 2017 · 6 comments · Fixed by #32262
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Milestone

Comments

@rmfrankch
Copy link

ISSUE TYPE
  • Bug Report
COMPONENT NAME

user module

ANSIBLE VERSION
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
CONFIGURATION

Nothing changed.

OS / ENVIRONMENT

Ubuntu 16.04LTS
local ansible run (local host only)
libuser 0.60 installed
Using the AD for authentication, users are defined in /etc/passwd => nsswitch.conf does NOT have sss for passwd, group, and shadow.

SUMMARY

I tried to create a local user using the user module with the local option (available as of 2.4).
This fails on Ubuntu 16.04LTS with the error:

Error parsing arguments: unknown option. 
Usage: luseradd [-irMn?] [-i|--interactive] [-r|--reserved]
 [-c|--gecos=STRING] [-d|--directory=STRING] [-k|--skeleton=STRING] 
 [-s|--shell=STRING] [-u|--uid=NUM] [-g|--gid=STRING]
 [-M|--nocreatehome] [-n|--nocreategroup] [-P|--plainpassword=STRING]
 [-p|--password=STRING] [--commonname=STRING] [--givenname=STRING]
 [--surname=STRING] [--roomnumber=STRING] [--telephonenumber=STRING] 
 [--homephone=STRING] [-?|--help] [--usage] [OPTION...] user


This works if local is false.

STEPS TO REPRODUCE

Install libuser if not installed
Add a new user to the local /etc/passwd file using the user module and the local option set to true.

  user:
    comment: "{{ item.gecos }},{{ dmi_users.org_unit }}"
    createhome: true
    group: "{{ item.gid }}"
    groups: "{{ item.groups|join(\",\") }}"
    append: false
    home: "{{ item.home }}"
    name: "{{ item.uid }}"
    password: "KB"
    shell: "{{ item.shell }}"
    state: "present"
    uid: "{{ item.uidnumber }}"
    local: true
  with_items: "{{ users }}"

users contains one full user record. This works fine with local: false

EXPECTED RESULTS

To add the user just as with local:false.

ACTUAL RESULTS

The module fails with the above error message.


@ansibot
Copy link
Contributor

ansibot commented Oct 26, 2017

cc @sfromm
click here for bot help

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 26, 2017
@nitzmahone nitzmahone added this to the 2.4.0 milestone Oct 26, 2017
@nitzmahone
Copy link
Member

@rmfrankch FYI, the reason it's failing is because luseradd doesn't support -m (which is its default behavior). As a temporary workaround, you can add createhome: false to get it working (it'll still create the homedir), but this won't work in the future if we fix this properly (since both useradd and luseradd seem to support -M (don't create home dir)), which we'd probably just switch to...

@nitzmahone
Copy link
Member

cc @bcoca - looks like you added the local support. It looks like there are several easy ways to fix this, though I'm not sure what'd be best supported across the various distros...

@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Oct 26, 2017
@rmfrankch
Copy link
Author

@nitzmahone: Unfortunately the workaround won't work, as I have both cases: with and without creating homes using the user module. Your suggestion would mean that I cannot use the local option if I don't want to create the homes.
So, this option is a blocker until fixed.

@bcoca
Copy link
Member

bcoca commented Oct 27, 2017

so we need to make it -M when luser? many 'useradd' implementations only support -m, not -M

does lusermod have the same issues?

@bcoca
Copy link
Member

bcoca commented Oct 27, 2017

this patch should fix

diff --git a/lib/ansible/modules/system/user.py b/lib/ansible/modules/system/user.py
index 6208d2394e..d0189ac548 100644
--- a/lib/ansible/modules/system/user.py
+++ b/lib/ansible/modules/system/user.py
@@ -424,7 +424,10 @@ class User(object):
             cmd.append(self.password)

         if self.create_home:
-            cmd.append('-m')
+            if self.local:
+                cmd.append('-M')
+            else:
+                cmd.append('-m')

             if self.skeleton is not None:
                 cmd.append('-k')

bcoca added a commit to bcoca/ansible that referenced this issue Oct 27, 2017
bcoca added a commit that referenced this issue Oct 31, 2017
fixes #32199

(cherry picked from commit bd321a0)
bcoca added a commit that referenced this issue Oct 31, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants