1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/shutdown/tasks/main.yml
Amin Vakil b25f0f3cd2 New module: shutdown (#700)
* New module: shutdown

* Add symlink to plugin

* Fix

Signed-off-by: Amin Vakil <info@aminvakil.com>

* Fix

* Fix

* Add seealso

* Fix seealso

* Add future-import, metaclass boilerplate

* Change pre_shutdown_delay to delay

* Cleanup before executing shutdown

* Fix

* Remove unused connect_timeout paramater

* Improve documentation

* Remove deprecated function and calling it

* Remove double calling delay function

* Remove unneeded call in check delay function

* Make check mode more realistic

* Remove extra blank line

* Remove unnecessary imports and fix copyright year

* Add shutdown_command and integration test

* Fix integration test

* Don't fail on local AND enabled check_mode

* Add copyright

* Skip ubuntu1804 as systemd-sysv is not installed on container

* Ignore ubuntu 18 on task

* Readd integration tests

* Do not run integration test on ubuntu 18

* Improve integration test and add delay, msg testing

* Fix ubuntu 18 integration test

* Remove unnecessary condition

(cherry picked from commit c475effeed)
2020-08-18 08:29:38 +02:00

84 lines
2.8 KiB
YAML

---
- name: Install systemd-sysv on ubuntu 18
apt:
name: systemd-sysv
state: present
when: ansible_distribution == 'Ubuntu' and ansible_distribution_major_version is version('18', '>=')
register: systemd_sysv_install
- name: Execute shutdown with custom message and delay
community.general.shutdown:
delay: 100
msg: "Custom Message"
register: shutdown_result
check_mode: yes
- name: Execute shutdown with minus delay
community.general.shutdown:
delay: -100
register: shutdown_result_minus
check_mode: yes
- name: Verify Custom Message except Alpine, AIX
assert:
that:
- '"Custom Message" in shutdown_result["shutdown_command"]'
- '"Shut down initiated by Ansible" in shutdown_result_minus["shutdown_command"]'
- '"Custom Message" not in shutdown_result_minus["shutdown_command"]'
when: ansible_os_family not in ['Alpine', 'AIX']
- name: Verify shutdown command is present except Alpine, VMKernel
assert:
that: '"shutdown" in shutdown_result["shutdown_command"]'
when: ansible_os_family != 'Alpine' and ansible_system != 'VMKernel'
- name: Verify shutdown command is present in Alpine
assert:
that: '"poweroff" in shutdown_result["shutdown_command"]'
when: ansible_os_family == 'Alpine'
- name: Verify shutdown command is present in VMKernel
assert:
that: '"halt" in shutdown_result["shutdown_command"]'
when: ansible_system == 'VMKernel'
- name: Verify shutdown delay is present in minutes in Linux
assert:
that:
- '"-h 1" in shutdown_result["shutdown_command"]'
- '"-h 0" in shutdown_result_minus["shutdown_command"]'
when: ansible_system == 'Linux' and ansible_os_family != 'Alpine'
- name: Verify shutdown delay is present in minutes in Void, MacOSX, OpenBSD
assert:
that:
- '"-h +1" in shutdown_result["shutdown_command"]'
- '"-h +0" in shutdown_result_minus["shutdown_command"]'
when: ansible_system in ['Void', 'MacOSX', 'OpenBSD']
- name: Verify shutdown delay is present in seconds in FreeBSD
assert:
that:
- '"-h +100s" in shutdown_result["shutdown_command"]'
- '"-h +0s" in shutdown_result_minus["shutdown_command"]'
when: ansible_system == 'FreeBSD'
- name: Verify shutdown delay is present in seconds in Solaris, SunOS
assert:
that:
- '"-g 100" in shutdown_result["shutdown_command"]'
- '"-g 0" in shutdown_result_minus["shutdown_command"]'
when: ansible_system in ['Solaris', 'SunOS']
- name: Verify shutdown delay is present in seconds, VMKernel
assert:
that:
- '"-d 100" in shutdown_result["shutdown_command"]'
- '"-d 0" in shutdown_result_minus["shutdown_command"]'
when: ansible_system == 'VMKernel'
- name: Remove systemd_sysv in ubuntu 18 in case it has been installed in test
apt:
name: systemd-sysv
state: absent
when: systemd_sysv_install is changed