0

Lets assume the following commands which will add three users. The first one will be created automatically with proper uid assignment. Afterwards I define a second user which needs to have a specific uid due to reasons. At last I add a third user but this will get an automatic assigned uid continued in the range from the manual uid assignment before.

To demonstrate I'll use this simple 3 step task

- name: Testuser01
  ansible.builtin.user:
    name: "testuserone"
    comment: "Created by Ansible"
    state: present

- name: Testuser02
  ansible.builtin.user:
    name: "testusertwo"
    uid: "2000"
    comment: "Created by Ansible"
    state: present

- name: Testuser03
  ansible.builtin.user:
    name: "testuserthree"
    comment: "Created by Ansible"
    state: present

Results in

testuserone:x:1000:1000:Created by Ansible
testusertwo:x:2000:2000:Created by Ansible
testuserthree:x:2001:2001:Created by Ansible

Expected result

testuserone:x:1000:1000:Created by Ansible
testusertwo:x:2000:2000:Created by Ansible
testuserthree:x:1001:1001:Created by Ansible

I would have expected that it continues from 1001 for testuserthree, but instead it gets the uid 2001. This is the default behavior from useradd for what I know.

Is it possible without a module patch or hack to get the ansible.builtin.user module to behave like adduser instead which continues to count+ in the lower range?

Sefer
  • 1
  • 1
  • _This is the default behavior from useradd for what I know_ > testing this assumption on a Debian container proves it incorrect. `useradd user1; useradd --uid 2000 user2; useradd user3; id --user user1; id --user user2; id --user user3` yield me `1000 2000 2001`. – β.εηοιτ.βε Sep 01 '23 at 20:36
  • Looks like a wording issue, sorry. The last sentence correlates to *but instead it gets the uid 2001* which is as proven the default behavior from useradd. I would like to see a behavior similar to adduser. – Sefer Sep 02 '23 at 09:39
  • _I would like to see a behavior similar to adduser._ > you are getting it already. – β.εηοιτ.βε Sep 02 '23 at 09:56
  • I do not. useradd results in *1000 2000 2001* and I expect *1000 2000 1001* as per adduser. I added the expected result to make it clear. – Sefer Sep 02 '23 at 12:24
  • And, as my first comment says, your assumption about the behaviour of `useradd` is wrong. Read my first comment carefully. – β.εηοιτ.βε Sep 02 '23 at 13:12
  • You use useradd to add three users. They yield *1000 2000 2001* which confirms my assumption of the useradd and therefore *ansible.builtin.user* behavior. I do not see where I am misinterpreting your comment. This is exactly the behavior which I do not want or expect. – Sefer Sep 02 '23 at 16:47

0 Answers0