You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/group/tasks/tests.yml

195 lines
4.6 KiB
YAML

---
##
## 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:
name: ansibullgroup
state: present
register: create_group_again
- name: assert create group (idempotent)
assert:
that:
- not create_group_again is changed
##
## group check
##
- 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
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)
assert:
that:
- not create_group_gid_again is changed
- create_group_gid_again.gid | int == gid.stdout_lines[0] | int
- 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: 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
when: ansible_facts.system != 'Darwin'
##
## group remove
##
- name: delete group (check mode)
group:
name: ansibullgroup
state: absent
register: delete_group_check
check_mode: True
- name: get result of delete group (check mode)
script: grouplist.sh "{{ ansible_distribution }}"
register: delete_group_actual_check
- name: assert delete group (check mode)
assert:
that:
- delete_group_check is changed
- '"ansibullgroup" in delete_group_actual_check.stdout_lines'
- name: delete group
group:
name: ansibullgroup
state: absent
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:
name: ansibullgroup
state: absent
register: delete_group_again
- name: assert delete group (idempotent)
assert:
that:
- not delete_group_again is changed