How to change ansible user module uid behavior after manual additions

102 views Asked by At

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?

0

There are 0 answers