fix(tasks): accept an integer gid when creating a unix group
The two group tasks differed only in whether `gid` was passed, and the branch between them tested `unix_group.value.gid | length`. The length filter has no meaning for an integer and raises "object of type 'int' has no len()". The example in defaults/main.yaml declares `gid: 1001` unquoted, so the documented usage aborted the run, while the quoted variant in the README happened to work. Both tasks are merged into one that passes the gid through `default(omit, true)`. The boolean form of the filter is required to keep the previous meaning of an empty gid, which is to let the system assign one. The only value that changes semantics is gid 0, which is the root group and outside the scope of this role. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -1,14 +1,8 @@
|
||||
---
|
||||
|
||||
- name: "Create unix group with random gid: {{ unix_group.key }}"
|
||||
- name: "Create unix group: {{ unix_group.key }}"
|
||||
ansible.builtin.group:
|
||||
name: "{{ unix_group.key }}"
|
||||
# The boolean form of default also omits an empty gid, which means let the system assign one.
|
||||
gid: "{{ unix_group.value.gid | default(omit, true) }}"
|
||||
state: "{{ unix_group.value.state | default('present') }}"
|
||||
when: unix_group.value.gid is not defined or unix_group.value.gid is defined and unix_group.value.gid | length <= 0
|
||||
|
||||
- name: "Create unix group with pre-defined gid: {{ unix_group.key }}"
|
||||
ansible.builtin.group:
|
||||
name: "{{ unix_group.key }}"
|
||||
gid: "{{ unix_group.value.gid }}"
|
||||
state: "{{ unix_group.value.state | default('present') }}"
|
||||
when: unix_group.value.gid is defined and unix_group.value.gid | length > 0
|
||||
|
||||
Reference in New Issue
Block a user