d1472289c2
Systemd provides for "timers" which is replacing cron. This change implements timers as an option to any created service. Change-Id: I8fdca58fcb43726560521c7c25f7e57cfb61353b Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
148 lines
4.9 KiB
YAML
148 lines
4.9 KiB
YAML
---
|
|
# Copyright 2015, Rackspace US, Inc.
|
|
# Copyright 2018, Logan Vig <logan2211@gmail.com>
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
- name: Playbook for role testing
|
|
hosts: localhost
|
|
connection: local
|
|
user: root
|
|
become: true
|
|
roles:
|
|
- role: "systemd_service"
|
|
systemd_services:
|
|
- service_name: "test simple service0"
|
|
execstarts: "/bin/bash -c 'while true; do sleep 2 && echo test simple service; done'"
|
|
enabled: yes
|
|
- service_name: "test oneshot service0"
|
|
config_overrides:
|
|
Unit:
|
|
Description: Test oneshot service
|
|
After: network-online.target
|
|
Wants: network-online.target
|
|
Service:
|
|
RemainAfterExit: yes
|
|
service_type: oneshot
|
|
execstarts:
|
|
- "/bin/bash -c 'echo start1'"
|
|
- "/bin/bash -c 'echo start2'"
|
|
execstops:
|
|
- "/bin/bash -c 'echo stop1'"
|
|
- "/bin/bash -c 'echo stop2'"
|
|
enabled: yes
|
|
state: started
|
|
systemd_tempd_prefix: openstack
|
|
systemd_lock_path: /var/lock/networking
|
|
- service_name: "test timer service0"
|
|
execstarts:
|
|
- "/bin/bash -c 'echo start0'"
|
|
timer:
|
|
state: "started"
|
|
options:
|
|
OnBootSec: 30min
|
|
OnUnitActiveSec: 1h
|
|
Persistent: true
|
|
- service_name: "test timer service1"
|
|
execstarts:
|
|
- "/bin/bash -c 'echo start1'"
|
|
timer:
|
|
state: "started"
|
|
cron_minute: 30
|
|
cron_hour: 1
|
|
|
|
post_tasks:
|
|
- name: Check Services
|
|
command: systemctl status "{{ item }}"
|
|
changed_when: false
|
|
with_items:
|
|
- test_simple_service0
|
|
- test_oneshot_service0
|
|
- test_timer_service0.timer
|
|
- test_timer_service1.timer
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Test failure condition
|
|
block:
|
|
- name: Run the systemd service role
|
|
include_role:
|
|
name: systemd_service
|
|
private: true
|
|
vars:
|
|
systemd_services:
|
|
- service_name: "test simple service1"
|
|
execstarts:
|
|
- "/bin/bash -c 'while true; do sleep 2 && echo test simple service1; done'"
|
|
- "/bin/bash -c 'while true; do sleep 2 && echo test simple service2; done'"
|
|
rescue:
|
|
- name: Set negative service test pass fact
|
|
set_fact:
|
|
systemd_service_execstarts_test: true
|
|
|
|
- name: Test failure condition
|
|
block:
|
|
- name: Run the systemd service role
|
|
include_role:
|
|
name: systemd_service
|
|
private: true
|
|
vars:
|
|
systemd_services:
|
|
- service_name: "test simple service2"
|
|
execstarts: "/bin/bash -c 'while true; do sleep 2 && echo test simple service; done'"
|
|
execstops:
|
|
- /bin/true
|
|
- /bin/true
|
|
rescue:
|
|
- name: Set negative service test pass fact
|
|
set_fact:
|
|
systemd_service_execstops_test: true
|
|
|
|
- name: Test failure condition
|
|
block:
|
|
- name: Run the systemd service role
|
|
include_role:
|
|
name: systemd_service
|
|
private: true
|
|
vars:
|
|
systemd_services:
|
|
- service_name: "test simple service3"
|
|
execstarts: "/bin/true"
|
|
execreloads:
|
|
- /bin/true
|
|
- /bin/true
|
|
rescue:
|
|
- name: Set negative service test pass fact
|
|
set_fact:
|
|
systemd_service_execreloads_test: true
|
|
|
|
- name: Check negative service testing
|
|
fail:
|
|
msg: >-
|
|
Failed negative service testing. Results --
|
|
systemd_service_execstarts_test: {{ systemd_service_execstarts_test }},
|
|
systemd_service_execstops_test: {{ systemd_service_execstops_test }},
|
|
systemd_service_execreloads_test: {{ systemd_service_execreloads_test }}
|
|
when:
|
|
- (not systemd_service_execstarts_test | bool) or
|
|
(not systemd_service_execstops_test | bool) or
|
|
(not systemd_service_execreloads_test | bool)
|
|
|
|
- name: Notify tests passed
|
|
debug:
|
|
msg: All tests have passed
|
|
vars:
|
|
systemd_service_execstarts_test: false
|
|
systemd_service_execstops_test: false
|
|
systemd_service_execreloads_test: false
|