Closed kaysond closed 2 years ago
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @samdoran @sfromm click here for bot help
@kaysond
How about removing the parameter "local=yes"? I did well.
https://docs.ansible.com/ansible/latest/modules/user_module.html#user-module "Mutually exclusive with groups and append"
[root@localhost ansible]# ansible localhost -bkK -m "user" -a "name=testuser state=present group=group1"
SSH password:
BECOME password[defaults to SSH password]:
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | SUCCESS => {
"append": false,
"changed": false,
"comment": "testuser",
"group": 159,
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
[root@localhost ansible]# ansible localhost -bkK -m "user" -a "name=testuser state=present group=group2"
SSH password:
BECOME password[defaults to SSH password]:
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | CHANGED => {
"append": false,
"changed": true,
"comment": "testuser",
"group": 160,
"home": "/home/testuser",
"move_home": false,
"name": "testuser",
"shell": "/bin/bash",
"state": "present",
"uid": 1001
}
@yuji-k64613 I need to use "local" because the system uses LDAP, but I want to create local users for permissions management of various services. So it needs to use luseradd
@kaysond
I don't think this error is Ansible issue.
Ansible execute this command.
['/sbin/lusermod', '-g', 'group2', 'testuser']
I tried this command on bash.
$ lusermod -g group2 testuser
-> ERROR
$ lusermod -g 160 testuser
-> OK
If a group is a number, not a name, lusermod succeeds. So, Ansible succeeds, too.
If a group is a number, not a name, lusermod succeeds. So, Ansible succeeds, too.
But the first command works just fine, even though its a group name.
But the first command works just fine, even though its a group name.
The first command don't execute "lusermod" so Ansible works just fine("changed": false).
The second command execute "lusermod" like this.
['/sbin/lusermod', '-g', 'group2', 'testuser']
If the group is different, the following code is executed.
721 if info[3] != ginfo[2]:
722 cmd.append('-g')
723 cmd.append(self.group)
Interesting. But in any case, its still a problem. The command should work with the same syntax whether the user exists or not, and whether it has the same or different primary group.
bump
Today I came to the same bug :(. And it seems that the current one is also a duplicate of #37396 . I was using Ansible 2.9.6.
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the !component
bot command.
Seems that since lusermod
only accepts a GID for -g
, we need to translate the group name into the GID when using lusermod
.
Seems that since
lusermod
only accepts a GID for-g
, we need to translate the group name into the GID when usinglusermod
.
As I mentioned in #37396, the lusermod -g
change only primary group and require gid.
To change additional groups, we need to use lgroupmod -M/-m
.
PS: The #37396 can't be duplicate of current issue (:
hopeless.
SUMMARY
running
ansible -m "user" -a "name=pihole state=present group=docker local=yes"
fails withInvalid group ID docker\nUsage: lusermod
...ISSUE TYPE
COMPONENT NAME
user
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Ubuntu 18.04.03
STEPS TO REPRODUCE
Create two groups on the host
group1
andgroup2
Run
ansible -i "192.168.1.10," -bkK -m "user" -a "name=testuser state=present group=group1 local=yes" all
(or equivalent)Then run
ansible -i "192.168.1.10," -bkK -m "user" -a "name=testuser state=present group=group2 local=yes" all
EXPECTED RESULTS
The second command should succeed and change the user's primary group to group2
ACTUAL RESULTS
It seems that for whatever reason ansible is calling lgroupmod with the group name, where it should be the group id (the module documentation asks for a group name).
The lusermod command on my system is installed via the package
libuser | 1:0.62~dfsg-0.1ubuntu2 | http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages