@ -1,135 +1,147 @@
---
##
## group add
##
- name : ensure test groups are deleted before the test
group:
name : '{{ item }}'
state : absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3
- name : create group (check mode)
- block:
##
## group add
##
- name : create group (check mode)
group:
name : ansibullgroup
state : present
register : create_group_check
check_mode : True
check_mode : t rue
- name : get result of create group (check mode)
- name : get result of create group (check mode)
script : 'grouplist.sh "{{ ansible_distribution }}"'
register : create_group_actual_check
- name : assert create group (check mode)
- name : assert create group (check mode)
assert:
that:
- create_group_check is changed
- '"ansibullgroup" not in create_group_actual_check.stdout_lines'
- name : create group
- name : create group
group:
name : ansibullgroup
state : present
register : create_group
- name : get result of create group
- name : get result of create group
script : 'grouplist.sh "{{ ansible_distribution }}"'
register : create_group_actual
- name : assert create group
- name : assert create group
assert:
that:
- create_group is changed
- create_group.gid is defined
- '"ansibullgroup" in create_group_actual.stdout_lines'
- name : create group (idempotent)
- name : create group (idempotent)
group:
name : ansibullgroup
state : present
register : create_group_again
- name : assert create group (idempotent)
- name : assert create group (idempotent)
assert:
that:
- not create_group_again is changed
##
## group check
##
##
## group check
##
- name : run existing group check tests
- name : run existing group check tests
group:
name : "{{ create_group_actual.stdout_lines|random }}"
state : present
with_sequence : start=1 end=5
register : group_test1
- name : validate results for testcase 1
- name : validate results for testcase 1
assert:
that:
- group_test1.results is defined
- group_test1.results|length == 5
- name : validate change results for testcase 1
- name : validate change results for testcase 1
assert:
that:
- not group_test1 is changed
##
## group add with gid
##
##
## group add with gid
##
- name : get the next available gid
script : g idg et.py
- name : get the next available gid
script : g et_free_gid .py
args:
executable : '{{ ansible_python_interpreter }}'
register : gid
- name : create a group with a gid (check mode)
- name : create a group with a gid (check mode)
group:
name : ansibullgroup2
gid : '{{ gid.stdout_lines[0] }}'
state : present
register : create_group_gid_check
check_mode : T rue
check_mode : t rue
- name : get result of create a group with a gid (check mode)
- name : get result of create a group with a gid (check mode)
script : 'grouplist.sh "{{ ansible_distribution }}"'
register : create_group_gid_actual_check
- name : assert create group with a gid (check mode)
- name : assert create group with a gid (check mode)
assert:
that:
- create_group_gid_check is changed
- '"ansibullgroup2" not in create_group_gid_actual_check.stdout_lines'
- name : create a group with a gid
- name : create a group with a gid
group:
name : ansibullgroup2
gid : '{{ gid.stdout_lines[0] }}'
state : present
register : create_group_gid
- name : get gid of created group
command : "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('ansibullgroup2').gr_gid)\""
- name : get gid of created group
script : "get_gid_for_group.py ansibullgroup2"
args:
executable : '{{ ansible_python_interpreter }}'
register : create_group_gid_actual
- name : assert create group with a gid
- name : assert create group with a gid
assert:
that:
- create_group_gid is changed
- create_group_gid.gid | int == gid.stdout_lines[0] | int
- create_group_gid_actual.stdout | trim | int == gid.stdout_lines[0] | int
- name : create a group with a gid (idempotent)
- name : create a group with a gid (idempotent)
group:
name : ansibullgroup2
gid : '{{ gid.stdout_lines[0] }}'
state : present
register : create_group_gid_again
- name : assert create group with a gid (idempotent)
- name : assert create group with a gid (idempotent)
assert:
that:
- not create_group_gid_again is changed
- create_group_gid_again.gid | int == gid.stdout_lines[0] | int
- block:
- block:
- name : create a group with a non-unique gid
group:
name : ansibullgroup3
@ -153,55 +165,55 @@
- missing_gid is failed
when : ansible_facts.distribution not in ['MacOSX', 'Alpine']
##
## group remove
##
##
## group remove
##
- name : delete group (check mode)
- name : delete group (check mode)
group:
name : ansibullgroup
state : absent
register : delete_group_check
check_mode : T rue
check_mode : t rue
- name : get result of delete group (check mode)
script : grouplist.sh "{{ ansible_distribution }}"
- name : get result of delete group (check mode)
script : 'grouplist.sh "{{ ansible_distribution }}"'
register : delete_group_actual_check
- name : assert delete group (check mode)
- name : assert delete group (check mode)
assert:
that:
- delete_group_check is changed
- '"ansibullgroup" in delete_group_actual_check.stdout_lines'
- name : delete group
- name : delete group
group:
name : ansibullgroup
state : absent
register : delete_group
- name : get result of delete group
script : grouplist.sh "{{ ansible_distribution }}"
- name : get result of delete group
script : 'grouplist.sh "{{ ansible_distribution }}"'
register : delete_group_actual
- name : assert delete group
- name : assert delete group
assert:
that:
- delete_group is changed
- '"ansibullgroup" not in delete_group_actual.stdout_lines'
- name : delete group (idempotent)
- name : delete group (idempotent)
group:
name : ansibullgroup
state : absent
register : delete_group_again
- name : assert delete group (idempotent)
- name : assert delete group (idempotent)
assert:
that:
- not delete_group_again is changed
- name : Ensure lgroupadd is present
- name : Ensure lgroupadd is present
action : "{{ ansible_facts.pkg_mgr }}"
args:
name : libuser
@ -210,23 +222,23 @@
tags:
- user_test_local_mode
- name : Ensure lgroupadd is present - Alpine
- name : Ensure lgroupadd is present - Alpine
command : apk add -U libuser
when : ansible_distribution == 'Alpine'
tags:
- user_test_local_mode
# https://github.com/ansible/ansible/issues/56481
- block:
# https://github.com/ansible/ansible/issues/56481
- block:
- name : Test duplicate GID with local=yes
group:
name : "{{ item }}"
gid : 1337
local : yes
local : true
loop:
- group1_local_test
- group2_local_test
ignore_errors : yes
ignore_errors : true
register : local_duplicate_gid_result
- assert:
@ -241,18 +253,20 @@
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
when : ansible_distribution == 'CentOS'
# https://github.com/ansible/ansible/pull/59769
- block:
# https://github.com/ansible/ansible/pull/59769
- block:
- name : create a local group with a gid
group:
name : group1_local_test
gid : 1337
local : yes
local : true
state : present
register : create_local_group_gid
- name : get gid of created local group
command : "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('group1_local_test').gr_gid)\""
script : "get_gid_for_group.py group1_local_test"
args:
executable : '{{ ansible_python_interpreter }}'
register : create_local_group_gid_actual
- name : assert create local group with a gid
@ -282,18 +296,20 @@
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
when : ansible_distribution == 'CentOS'
# https://github.com/ansible/ansible/pull/59772
- block:
# https://github.com/ansible/ansible/pull/59772
- block:
- name : create group with a gid
group:
name : group1_test
gid : 1337
local : no
local : false
state : present
register : create_group_gid
- name : get gid of created group
command : "{{ ansible_python_interpreter | quote }} -c \"import grp; print(grp.getgrnam('group1_test').gr_gid)\""
script : "get_gid_for_group.py group1_test"
args:
executable : '{{ ansible_python_interpreter }}'
register : create_group_gid_actual
- name : assert create group with a gid
@ -307,7 +323,7 @@
group:
name : group1_test
gid : 1337
local : yes
local : true
state : present
register : create_local_group_gid
@ -319,25 +335,35 @@
- name : Cleanup create group with a gid
group:
name : group1_test
local : no
local : false
state : absent
- name : Cleanup create local group with the same gid
group:
name : group1_test
local : yes
local : true
state : absent
# only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
when : ansible_distribution == 'CentOS'
# create system group
# create system group
- name : remove group
- name : remove group
group:
name : ansibullgroup
state : absent
- name : create system group
- name : create system group
group:
name : ansibullgroup
state : present
system : yes
system : true
always:
- name : remove test groups after test
group:
name : '{{ item }}'
state : absent
loop:
- ansibullgroup
- ansibullgroup2
- ansibullgroup3