robertdebock / ansible-role-users

The purpose of this role is to add users and groups on your system.
https://robertdebock.nl/
Apache License 2.0
43 stars 27 forks source link

"msg": "groupdel: cannot remove the primary group of user #25

Closed charnet1019 closed 1 year ago

charnet1019 commented 2 years ago

playbook:

---

- name: user mgr
  hosts: demo
  become: yes
  gather_facts: yes

  roles:
    - role: users
      users_user_list:
        - name: tim
          state: absent

      users_group_list:
        - name: tim
          state: absent
robertdebock commented 2 years ago

Acknowledged. This is caused by the order of calling the group.yml (first) and users.yml (second).

I'm not sure how to resolve this exact situation. Keeping the issue open for future reference.

A work-around can be to first define the user to delete:

- name: user mgr
  hosts: demo
  become: yes
  gather_facts: yes

  roles:
    - role: users
      users_user_list:
        - name: tim
          state: absent

Run ansible, and next run, define the group to delete:

- name: user mgr
  hosts: demo
  become: yes
  gather_facts: yes

  roles:
    - role: users
      users_group_list:
        - name: tim
          state: absent
robertdebock commented 1 year ago

It's going to be ugly to address this issue. I'm closing this as there was no further interest.

Thanks for brining it up though.