systemd: should fail in check_mode when service not found on host (#68136)
* systemd: should fail in check_mode when service not found on host
This commit is contained in:
parent
6a4455ff54
commit
00ead98595
5 changed files with 58 additions and 4 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- systemd - the module should fail in check_mode when service not found on host (https://github.com/ansible/ansible/pull/68136).
|
|
@ -114,10 +114,7 @@ def fail_if_missing(module, found, service, msg=''):
|
|||
:kw msg: extra info to append to error/success msg when missing
|
||||
'''
|
||||
if not found:
|
||||
if module.check_mode:
|
||||
module.exit_json(msg="Service %s not found on %s, assuming it will exist on full run" % (service, msg), changed=True)
|
||||
else:
|
||||
module.fail_json(msg='Could not find the requested service %s: %s' % (service, msg))
|
||||
module.fail_json(msg='Could not find the requested service %s: %s' % (service, msg))
|
||||
|
||||
|
||||
def fork_process():
|
||||
|
|
|
@ -194,3 +194,32 @@
|
|||
that:
|
||||
- "remove_result.path == '/usr/sbin/ansible_test_service'"
|
||||
- "remove_result.state == 'absent'"
|
||||
|
||||
- name: the module must fail when a service is not found
|
||||
service:
|
||||
name: 'nonexisting'
|
||||
state: stopped
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
when: ansible_distribution != 'FreeBSD'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is search("Could not find the requested service nonexisting")
|
||||
when: ansible_distribution != 'FreeBSD'
|
||||
|
||||
- name: the module must fail in check_mode as well when a service is not found
|
||||
service:
|
||||
name: 'nonexisting'
|
||||
state: stopped
|
||||
register: result
|
||||
check_mode: yes
|
||||
ignore_errors: yes
|
||||
when: ansible_distribution != 'FreeBSD'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is search("Could not find the requested service nonexisting")
|
||||
when: ansible_distribution != 'FreeBSD'
|
||||
|
|
1
test/integration/targets/systemd/defaults/main.yml
Normal file
1
test/integration/targets/systemd/defaults/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
fake_service: nonexisting
|
|
@ -47,4 +47,29 @@
|
|||
- 'not systemd_test0.changed'
|
||||
- 'systemd_test0.state == "started"'
|
||||
|
||||
- name: the module must fail when a service is not found
|
||||
systemd:
|
||||
name: '{{ fake_service }}'
|
||||
state: stopped
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is search("Could not find the requested service {{ fake_service }}")
|
||||
|
||||
- name: the module must fail in check_mode as well when a service is not found
|
||||
systemd:
|
||||
name: '{{ fake_service }}'
|
||||
state: stopped
|
||||
register: result
|
||||
check_mode: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result is search("Could not find the requested service {{ fake_service }}")
|
||||
|
||||
when: 'systemctl_check.rc == 0'
|
||||
|
|
Loading…
Reference in a new issue