@ -20,70 +20,73 @@
## systemctl
## systemctl
##
##
- name : check for systemctl command
- name : End if this system does not use systemd
shell : which systemctl
meta : end_host
failed_when : False
when : ansible_facts.service_mgr != 'systemd'
register : systemctl_check
- name : Include distribution specific variables
- meta : end_host
include_vars : "{{ lookup('first_found', params) }}"
when : systemctl_check.rc != 0
vars:
params:
- set_fact:
files:
ssh_service : '{{ "ssh" if ansible_os_family == "Debian" else "sshd" }}'
- "{{ ansible_facts.distribution }}.yml"
- "{{ ansible_facts.os_family }}.yml"
- block:
- default.yml
- name : get a list of running services
paths:
shell : systemctl | fgrep 'running' | awk '{print $1}' | sed 's/\.service//g' | fgrep -v '.' | egrep ^[a-z]
- vars
register : running_names
- debug : var=running_names
- name : get a list of running services
shell : systemctl | fgrep 'running' | awk '{print $1}' | sed 's/\.service//g' | fgrep -v '.' | egrep ^[a-z]
- name : check running state
register : running_names
systemd:
- debug : var=running_names
name : "{{ running_names.stdout_lines|random }}"
state : started
- name : check running state
register : systemd_test0
systemd:
- debug : var=systemd_test0
name : "{{ running_names.stdout_lines|random }}"
- name : validate results for test0
state : started
assert:
register : systemd_test0
that:
- debug : var=systemd_test0
- 'systemd_test0.changed is defined'
- name : validate results for test0
- 'systemd_test0.name is defined'
assert:
- 'systemd_test0.state is defined'
that:
- 'systemd_test0.status is defined'
- 'systemd_test0.changed is defined'
- 'not systemd_test0.changed'
- 'systemd_test0.name is defined'
- 'systemd_test0.state == "started"'
- 'systemd_test0.state is defined'
- 'systemd_test0.status is defined'
- name : the module must fail when a service is not found
- 'not systemd_test0.changed'
systemd:
- 'systemd_test0.state == "started"'
name : '{{ fake_service }}'
state : stopped
- name : the module must fail when a service is not found
register : result
systemd:
ignore_errors : yes
name : '{{ fake_service }}'
state : stopped
- assert:
register : result
that:
ignore_errors : yes
- result is failed
- 'result is search("Could not find the requested service {{ fake_service }}")'
- assert:
that:
- name : the module must fail in check_mode as well when a service is not found
- result is failed
systemd:
- 'result is search("Could not find the requested service {{ fake_service }}")'
name : '{{ fake_service }}'
state : stopped
- name : the module must fail in check_mode as well when a service is not found
register : result
systemd:
check_mode : yes
name : '{{ fake_service }}'
ignore_errors : yes
state : stopped
register : result
- assert:
check_mode : yes
that:
ignore_errors : yes
- result is failed
- 'result is search("Could not find the requested service {{ fake_service }}")'
- assert:
that:
- name : check that the module works even when systemd is offline (eg in chroot)
- result is failed
systemd:
- 'result is search("Could not find the requested service {{ fake_service }}")'
name : "{{ running_names.stdout_lines|random }}"
state : started
- name : check that the module works even when systemd is offline (eg in chroot)
environment:
systemd:
SYSTEMD_OFFLINE : 1
name : "{{ running_names.stdout_lines|random }}"
state : started
environment:
SYSTEMD_OFFLINE : 1
- name : Disable ssh 1
- name : Disable ssh 1
systemd:
systemd:
@ -114,3 +117,5 @@
- systemd_disable_ssh_2 is not changed
- systemd_disable_ssh_2 is not changed
- systemd_enable_ssh_1 is changed
- systemd_enable_ssh_1 is changed
- systemd_enable_ssh_2 is not changed
- systemd_enable_ssh_2 is not changed
- import_tasks : test_unit_template.yml