mirror of https://github.com/ansible/ansible.git
Refactor structure of group module integration tests (#78652)
This to match the structure with the tests for the user module. When having the tests available as stand-alone tests, it will be easier to add more integration tests in the future.pull/78172/head
parent
196084773b
commit
a3531ac422
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import grp
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
gids = [g.gr_gid for g in grp.getgrall()]
|
||||||
|
|
||||||
|
# Start the gid numbering with 1
|
||||||
|
# FreeBSD doesn't support the usage of gid 0, it doesn't fail (rc=0) but instead a number in the normal
|
||||||
|
# range is picked.
|
||||||
|
i = 1
|
||||||
|
while True:
|
||||||
|
if i not in gids:
|
||||||
|
print(i)
|
||||||
|
break
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
from __future__ import (absolute_import, division, print_function)
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
import grp
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
group_name = None
|
||||||
|
if len(sys.argv) >= 2:
|
||||||
|
group_name = sys.argv[1]
|
||||||
|
|
||||||
|
print(grp.getgrnam(group_name).gr_gid)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@ -1,15 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import grp
|
|
||||||
|
|
||||||
gids = [g.gr_gid for g in grp.getgrall()]
|
|
||||||
|
|
||||||
i = 0
|
|
||||||
while True:
|
|
||||||
if i not in gids:
|
|
||||||
print(i)
|
|
||||||
break
|
|
||||||
i += 1
|
|
||||||
@ -1,343 +1,369 @@
|
|||||||
---
|
---
|
||||||
##
|
- name: ensure test groups are deleted before the test
|
||||||
## group add
|
|
||||||
##
|
|
||||||
|
|
||||||
- name: create group (check mode)
|
|
||||||
group:
|
|
||||||
name: ansibullgroup
|
|
||||||
state: present
|
|
||||||
register: create_group_check
|
|
||||||
check_mode: True
|
|
||||||
|
|
||||||
- name: get result of create group (check mode)
|
|
||||||
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
|
||||||
register: create_group_actual_check
|
|
||||||
|
|
||||||
- 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
|
|
||||||
group:
|
|
||||||
name: ansibullgroup
|
|
||||||
state: present
|
|
||||||
register: create_group
|
|
||||||
|
|
||||||
- name: get result of create group
|
|
||||||
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
|
||||||
register: create_group_actual
|
|
||||||
|
|
||||||
- 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)
|
|
||||||
group:
|
group:
|
||||||
name: ansibullgroup
|
name: '{{ item }}'
|
||||||
state: present
|
state: absent
|
||||||
register: create_group_again
|
loop:
|
||||||
|
- ansibullgroup
|
||||||
|
- ansibullgroup2
|
||||||
|
- ansibullgroup3
|
||||||
|
|
||||||
- name: assert create group (idempotent)
|
- block:
|
||||||
assert:
|
##
|
||||||
that:
|
## group add
|
||||||
- not create_group_again is changed
|
##
|
||||||
|
|
||||||
##
|
- name: create group (check mode)
|
||||||
## group check
|
group:
|
||||||
##
|
name: ansibullgroup
|
||||||
|
state: present
|
||||||
|
register: create_group_check
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
- name: run existing group check tests
|
- name: get result of create group (check mode)
|
||||||
group:
|
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
||||||
name: "{{ create_group_actual.stdout_lines|random }}"
|
register: create_group_actual_check
|
||||||
state: present
|
|
||||||
with_sequence: start=1 end=5
|
|
||||||
register: group_test1
|
|
||||||
|
|
||||||
- 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
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- not group_test1 is changed
|
|
||||||
|
|
||||||
##
|
|
||||||
## group add with gid
|
|
||||||
##
|
|
||||||
|
|
||||||
- name: get the next available gid
|
|
||||||
script: gidget.py
|
|
||||||
args:
|
|
||||||
executable: '{{ ansible_python_interpreter }}'
|
|
||||||
register: gid
|
|
||||||
|
|
||||||
- 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: True
|
|
||||||
|
|
||||||
- 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)
|
|
||||||
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
|
|
||||||
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)\""
|
|
||||||
register: create_group_gid_actual
|
|
||||||
|
|
||||||
- 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)
|
|
||||||
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 (check mode)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- not create_group_gid_again is changed
|
- create_group_check is changed
|
||||||
- create_group_gid_again.gid | int == gid.stdout_lines[0] | int
|
- '"ansibullgroup" not in create_group_actual_check.stdout_lines'
|
||||||
|
|
||||||
- block:
|
- name: create group
|
||||||
- name: create a group with a non-unique gid
|
|
||||||
group:
|
group:
|
||||||
name: ansibullgroup3
|
name: ansibullgroup
|
||||||
gid: '{{ gid.stdout_lines[0] }}'
|
|
||||||
non_unique: true
|
|
||||||
state: present
|
state: present
|
||||||
register: create_group_gid_non_unique
|
register: create_group
|
||||||
|
|
||||||
- name: validate gid required with non_unique
|
- name: get result of create group
|
||||||
|
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
||||||
|
register: create_group_actual
|
||||||
|
|
||||||
|
- 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)
|
||||||
group:
|
group:
|
||||||
name: foo
|
name: ansibullgroup
|
||||||
non_unique: true
|
state: present
|
||||||
register: missing_gid
|
register: create_group_again
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: assert create group with a non unique gid
|
- name: assert create group (idempotent)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- create_group_gid_non_unique is changed
|
- not create_group_again is changed
|
||||||
- create_group_gid_non_unique.gid | int == gid.stdout_lines[0] | int
|
|
||||||
- missing_gid is failed
|
|
||||||
when: ansible_facts.distribution not in ['MacOSX', 'Alpine']
|
|
||||||
|
|
||||||
##
|
##
|
||||||
## group remove
|
## group check
|
||||||
##
|
##
|
||||||
|
|
||||||
- name: delete group (check mode)
|
- name: run existing group check tests
|
||||||
group:
|
group:
|
||||||
name: ansibullgroup
|
name: "{{ create_group_actual.stdout_lines|random }}"
|
||||||
state: absent
|
state: present
|
||||||
register: delete_group_check
|
with_sequence: start=1 end=5
|
||||||
check_mode: True
|
register: group_test1
|
||||||
|
|
||||||
- name: get result of delete group (check mode)
|
- name: validate results for testcase 1
|
||||||
script: grouplist.sh "{{ ansible_distribution }}"
|
assert:
|
||||||
register: delete_group_actual_check
|
that:
|
||||||
|
- group_test1.results is defined
|
||||||
|
- group_test1.results|length == 5
|
||||||
|
|
||||||
- name: assert delete group (check mode)
|
- name: validate change results for testcase 1
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- delete_group_check is changed
|
- not group_test1 is changed
|
||||||
- '"ansibullgroup" in delete_group_actual_check.stdout_lines'
|
|
||||||
|
|
||||||
- name: delete group
|
##
|
||||||
group:
|
## group add with gid
|
||||||
name: ansibullgroup
|
##
|
||||||
state: absent
|
|
||||||
register: delete_group
|
|
||||||
|
|
||||||
- name: get result of delete group
|
- name: get the next available gid
|
||||||
script: grouplist.sh "{{ ansible_distribution }}"
|
script: get_free_gid.py
|
||||||
register: delete_group_actual
|
args:
|
||||||
|
executable: '{{ ansible_python_interpreter }}'
|
||||||
|
register: gid
|
||||||
|
|
||||||
- name: assert delete group
|
- name: create a group with a gid (check mode)
|
||||||
assert:
|
group:
|
||||||
that:
|
name: ansibullgroup2
|
||||||
- delete_group is changed
|
gid: '{{ gid.stdout_lines[0] }}'
|
||||||
- '"ansibullgroup" not in delete_group_actual.stdout_lines'
|
state: present
|
||||||
|
register: create_group_gid_check
|
||||||
|
check_mode: true
|
||||||
|
|
||||||
- name: delete group (idempotent)
|
- name: get result of create a group with a gid (check mode)
|
||||||
group:
|
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
||||||
name: ansibullgroup
|
register: create_group_gid_actual_check
|
||||||
state: absent
|
|
||||||
register: delete_group_again
|
- name: assert create group with a gid (check mode)
|
||||||
|
assert:
|
||||||
- name: assert delete group (idempotent)
|
that:
|
||||||
assert:
|
- create_group_gid_check is changed
|
||||||
that:
|
- '"ansibullgroup2" not in create_group_gid_actual_check.stdout_lines'
|
||||||
- not delete_group_again is changed
|
|
||||||
|
- name: create a group with a gid
|
||||||
- name: Ensure lgroupadd is present
|
|
||||||
action: "{{ ansible_facts.pkg_mgr }}"
|
|
||||||
args:
|
|
||||||
name: libuser
|
|
||||||
state: present
|
|
||||||
when: ansible_facts.system in ['Linux'] and ansible_distribution != 'Alpine' and ansible_os_family != 'Suse'
|
|
||||||
tags:
|
|
||||||
- user_test_local_mode
|
|
||||||
|
|
||||||
- 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:
|
|
||||||
- name: Test duplicate GID with local=yes
|
|
||||||
group:
|
|
||||||
name: "{{ item }}"
|
|
||||||
gid: 1337
|
|
||||||
local: yes
|
|
||||||
loop:
|
|
||||||
- group1_local_test
|
|
||||||
- group2_local_test
|
|
||||||
ignore_errors: yes
|
|
||||||
register: local_duplicate_gid_result
|
|
||||||
|
|
||||||
- assert:
|
|
||||||
that:
|
|
||||||
- local_duplicate_gid_result['results'][0] is success
|
|
||||||
- local_duplicate_gid_result['results'][1]['msg'] == "GID '1337' already exists with group 'group1_local_test'"
|
|
||||||
always:
|
|
||||||
- name: Cleanup
|
|
||||||
group:
|
group:
|
||||||
name: group1_local_test
|
name: ansibullgroup2
|
||||||
state: absent
|
gid: '{{ gid.stdout_lines[0] }}'
|
||||||
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
|
state: present
|
||||||
when: ansible_distribution == 'CentOS'
|
register: create_group_gid
|
||||||
|
|
||||||
# https://github.com/ansible/ansible/pull/59769
|
- name: get gid of created group
|
||||||
- block:
|
script: "get_gid_for_group.py ansibullgroup2"
|
||||||
- name: create a local group with a gid
|
args:
|
||||||
group:
|
executable: '{{ ansible_python_interpreter }}'
|
||||||
name: group1_local_test
|
register: create_group_gid_actual
|
||||||
gid: 1337
|
|
||||||
local: yes
|
- name: assert create group with a gid
|
||||||
state: present
|
assert:
|
||||||
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)\""
|
|
||||||
register: create_local_group_gid_actual
|
|
||||||
|
|
||||||
- name: assert create local group with a gid
|
|
||||||
assert:
|
|
||||||
that:
|
that:
|
||||||
- create_local_group_gid is changed
|
- create_group_gid is changed
|
||||||
- create_local_group_gid.gid | int == 1337 | int
|
- create_group_gid.gid | int == gid.stdout_lines[0] | int
|
||||||
- create_local_group_gid_actual.stdout | trim | int == 1337 | int
|
- create_group_gid_actual.stdout | trim | int == gid.stdout_lines[0] | int
|
||||||
|
|
||||||
- name: create a local group with a gid (idempotent)
|
- name: create a group with a gid (idempotent)
|
||||||
group:
|
group:
|
||||||
name: group1_local_test
|
name: ansibullgroup2
|
||||||
gid: 1337
|
gid: '{{ gid.stdout_lines[0] }}'
|
||||||
state: present
|
state: present
|
||||||
register: create_local_group_gid_again
|
register: create_group_gid_again
|
||||||
|
|
||||||
- name: assert create local group with a gid (idempotent)
|
- name: assert create group with a gid (idempotent)
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- not create_local_group_gid_again is changed
|
- not create_group_gid_again is changed
|
||||||
- create_local_group_gid_again.gid | int == 1337 | int
|
- create_group_gid_again.gid | int == gid.stdout_lines[0] | int
|
||||||
always:
|
|
||||||
- name: Cleanup create local group with a gid
|
- block:
|
||||||
|
- name: create a group with a non-unique gid
|
||||||
|
group:
|
||||||
|
name: ansibullgroup3
|
||||||
|
gid: '{{ gid.stdout_lines[0] }}'
|
||||||
|
non_unique: true
|
||||||
|
state: present
|
||||||
|
register: create_group_gid_non_unique
|
||||||
|
|
||||||
|
- name: validate gid required with non_unique
|
||||||
|
group:
|
||||||
|
name: foo
|
||||||
|
non_unique: true
|
||||||
|
register: missing_gid
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: assert create group with a non unique gid
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- create_group_gid_non_unique is changed
|
||||||
|
- create_group_gid_non_unique.gid | int == gid.stdout_lines[0] | int
|
||||||
|
- missing_gid is failed
|
||||||
|
when: ansible_facts.distribution not in ['MacOSX', 'Alpine']
|
||||||
|
|
||||||
|
##
|
||||||
|
## group remove
|
||||||
|
##
|
||||||
|
|
||||||
|
- name: delete group (check mode)
|
||||||
group:
|
group:
|
||||||
name: group1_local_test
|
name: ansibullgroup
|
||||||
state: absent
|
state: absent
|
||||||
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
|
register: delete_group_check
|
||||||
when: ansible_distribution == 'CentOS'
|
check_mode: true
|
||||||
|
|
||||||
# https://github.com/ansible/ansible/pull/59772
|
- name: get result of delete group (check mode)
|
||||||
- block:
|
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
||||||
- name: create group with a gid
|
register: delete_group_actual_check
|
||||||
group:
|
|
||||||
name: group1_test
|
- name: assert delete group (check mode)
|
||||||
gid: 1337
|
assert:
|
||||||
local: no
|
|
||||||
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)\""
|
|
||||||
register: create_group_gid_actual
|
|
||||||
|
|
||||||
- name: assert create group with a gid
|
|
||||||
assert:
|
|
||||||
that:
|
|
||||||
- create_group_gid is changed
|
|
||||||
- create_group_gid.gid | int == 1337 | int
|
|
||||||
- create_group_gid_actual.stdout | trim | int == 1337 | int
|
|
||||||
|
|
||||||
- name: create local group with the same gid
|
|
||||||
group:
|
|
||||||
name: group1_test
|
|
||||||
gid: 1337
|
|
||||||
local: yes
|
|
||||||
state: present
|
|
||||||
register: create_local_group_gid
|
|
||||||
|
|
||||||
- name: assert create local group with a gid
|
|
||||||
assert:
|
|
||||||
that:
|
that:
|
||||||
- create_local_group_gid.gid | int == 1337 | int
|
- delete_group_check is changed
|
||||||
always:
|
- '"ansibullgroup" in delete_group_actual_check.stdout_lines'
|
||||||
- name: Cleanup create group with a gid
|
|
||||||
|
- name: delete group
|
||||||
group:
|
group:
|
||||||
name: group1_test
|
name: ansibullgroup
|
||||||
local: no
|
|
||||||
state: absent
|
state: absent
|
||||||
- name: Cleanup create local group with the same gid
|
register: delete_group
|
||||||
|
|
||||||
|
- name: get result of delete group
|
||||||
|
script: 'grouplist.sh "{{ ansible_distribution }}"'
|
||||||
|
register: delete_group_actual
|
||||||
|
|
||||||
|
- name: assert delete group
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- delete_group is changed
|
||||||
|
- '"ansibullgroup" not in delete_group_actual.stdout_lines'
|
||||||
|
|
||||||
|
- name: delete group (idempotent)
|
||||||
group:
|
group:
|
||||||
name: group1_test
|
name: ansibullgroup
|
||||||
local: yes
|
|
||||||
state: absent
|
state: absent
|
||||||
# only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
|
register: delete_group_again
|
||||||
when: ansible_distribution == 'CentOS'
|
|
||||||
|
|
||||||
# create system group
|
- name: assert delete group (idempotent)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not delete_group_again is changed
|
||||||
|
|
||||||
- name: remove group
|
- name: Ensure lgroupadd is present
|
||||||
group:
|
action: "{{ ansible_facts.pkg_mgr }}"
|
||||||
name: ansibullgroup
|
args:
|
||||||
state: absent
|
name: libuser
|
||||||
|
state: present
|
||||||
|
when: ansible_facts.system in ['Linux'] and ansible_distribution != 'Alpine' and ansible_os_family != 'Suse'
|
||||||
|
tags:
|
||||||
|
- user_test_local_mode
|
||||||
|
|
||||||
|
- 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:
|
||||||
|
- name: Test duplicate GID with local=yes
|
||||||
|
group:
|
||||||
|
name: "{{ item }}"
|
||||||
|
gid: 1337
|
||||||
|
local: true
|
||||||
|
loop:
|
||||||
|
- group1_local_test
|
||||||
|
- group2_local_test
|
||||||
|
ignore_errors: true
|
||||||
|
register: local_duplicate_gid_result
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- local_duplicate_gid_result['results'][0] is success
|
||||||
|
- local_duplicate_gid_result['results'][1]['msg'] == "GID '1337' already exists with group 'group1_local_test'"
|
||||||
|
always:
|
||||||
|
- name: Cleanup
|
||||||
|
group:
|
||||||
|
name: group1_local_test
|
||||||
|
state: absent
|
||||||
|
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
|
||||||
|
when: ansible_distribution == 'CentOS'
|
||||||
|
|
||||||
|
# https://github.com/ansible/ansible/pull/59769
|
||||||
|
- block:
|
||||||
|
- name: create a local group with a gid
|
||||||
|
group:
|
||||||
|
name: group1_local_test
|
||||||
|
gid: 1337
|
||||||
|
local: true
|
||||||
|
state: present
|
||||||
|
register: create_local_group_gid
|
||||||
|
|
||||||
|
- name: get gid of created local group
|
||||||
|
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
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- create_local_group_gid is changed
|
||||||
|
- create_local_group_gid.gid | int == 1337 | int
|
||||||
|
- create_local_group_gid_actual.stdout | trim | int == 1337 | int
|
||||||
|
|
||||||
|
- name: create a local group with a gid (idempotent)
|
||||||
|
group:
|
||||||
|
name: group1_local_test
|
||||||
|
gid: 1337
|
||||||
|
state: present
|
||||||
|
register: create_local_group_gid_again
|
||||||
|
|
||||||
|
- name: assert create local group with a gid (idempotent)
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- not create_local_group_gid_again is changed
|
||||||
|
- create_local_group_gid_again.gid | int == 1337 | int
|
||||||
|
always:
|
||||||
|
- name: Cleanup create local group with a gid
|
||||||
|
group:
|
||||||
|
name: group1_local_test
|
||||||
|
state: absent
|
||||||
|
# only applicable to Linux, limit further to CentOS where 'luseradd' is installed
|
||||||
|
when: ansible_distribution == 'CentOS'
|
||||||
|
|
||||||
|
# https://github.com/ansible/ansible/pull/59772
|
||||||
|
- block:
|
||||||
|
- name: create group with a gid
|
||||||
|
group:
|
||||||
|
name: group1_test
|
||||||
|
gid: 1337
|
||||||
|
local: false
|
||||||
|
state: present
|
||||||
|
register: create_group_gid
|
||||||
|
|
||||||
|
- name: get gid of created group
|
||||||
|
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
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- create_group_gid is changed
|
||||||
|
- create_group_gid.gid | int == 1337 | int
|
||||||
|
- create_group_gid_actual.stdout | trim | int == 1337 | int
|
||||||
|
|
||||||
|
- name: create local group with the same gid
|
||||||
|
group:
|
||||||
|
name: group1_test
|
||||||
|
gid: 1337
|
||||||
|
local: true
|
||||||
|
state: present
|
||||||
|
register: create_local_group_gid
|
||||||
|
|
||||||
|
- name: assert create local group with a gid
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- create_local_group_gid.gid | int == 1337 | int
|
||||||
|
always:
|
||||||
|
- name: Cleanup create group with a gid
|
||||||
|
group:
|
||||||
|
name: group1_test
|
||||||
|
local: false
|
||||||
|
state: absent
|
||||||
|
- name: Cleanup create local group with the same gid
|
||||||
|
group:
|
||||||
|
name: group1_test
|
||||||
|
local: true
|
||||||
|
state: absent
|
||||||
|
# only applicable to Linux, limit further to CentOS where 'lgroupadd' is installed
|
||||||
|
when: ansible_distribution == 'CentOS'
|
||||||
|
|
||||||
|
# create system group
|
||||||
|
|
||||||
|
- name: remove group
|
||||||
|
group:
|
||||||
|
name: ansibullgroup
|
||||||
|
state: absent
|
||||||
|
|
||||||
- name: create system group
|
- name: create system group
|
||||||
group:
|
group:
|
||||||
name: ansibullgroup
|
name: ansibullgroup
|
||||||
state: present
|
state: present
|
||||||
system: yes
|
system: true
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: remove test groups after test
|
||||||
|
group:
|
||||||
|
name: '{{ item }}'
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- ansibullgroup
|
||||||
|
- ansibullgroup2
|
||||||
|
- ansibullgroup3
|
||||||
|
|||||||
Loading…
Reference in New Issue