mirror of https://github.com/ansible/ansible.git
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.
155 lines
5.1 KiB
YAML
155 lines
5.1 KiB
YAML
11 years ago
|
- name: install the test daemon script
|
||
|
copy: src=ansible_test_service dest=/usr/sbin/ansible_test_service mode=755
|
||
|
register: install_result
|
||
|
|
||
|
- name: assert that the daemon script was installed
|
||
|
assert:
|
||
|
that:
|
||
|
- "install_result.dest == '/usr/sbin/ansible_test_service'"
|
||
|
- "install_result.state == 'file'"
|
||
|
- "install_result.mode == '0755'"
|
||
|
|
||
8 years ago
|
# determine init system is in use
|
||
|
- name: detect sysv init system
|
||
|
set_fact: service_type=sysv
|
||
9 years ago
|
when: ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and (ansible_distribution_version|version_compare('6', '>=') and ansible_distribution_version|version_compare('7', '<'))
|
||
8 years ago
|
- name: detect systemd init system
|
||
|
set_fact: service_type=systemd
|
||
9 years ago
|
when: (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and (ansible_distribution_version|version_compare('7', '>=') and ansible_distribution_version|version_compare('8', '<'))) or ansible_distribution == 'Fedora' or (ansible_distribution == 'Ubuntu' and ansible_distribution_version|version_compare('15.04', '>=')) or (ansible_distribution == 'Debian' and ansible_distribution_version|version_compare('8', '>=')) or ansible_os_family == 'Suse'
|
||
8 years ago
|
- name: detect upstart init system
|
||
|
set_fact: service_type=upstart
|
||
9 years ago
|
when: ansible_distribution == 'Ubuntu' and ansible_distribution_version|version_compare('15.04', '<')
|
||
11 years ago
|
|
||
8 years ago
|
# setup test service script
|
||
|
- include: 'sysv_setup.yml'
|
||
|
when: service_type == "sysv"
|
||
|
- include: 'systemd_setup.yml'
|
||
|
when: service_type == "systemd"
|
||
|
- include: 'upstart_setup.yml'
|
||
|
when: service_type == "upstart"
|
||
|
|
||
|
- name: disable the ansible test service
|
||
|
service: name=ansible_test enabled=no
|
||
|
|
||
|
- name: (check mode run) enable the ansible test service
|
||
|
service: name=ansible_test enabled=yes
|
||
|
register: enable_in_check_mode_result
|
||
|
check_mode: yes
|
||
|
|
||
|
- name: assert that changes reported for check mode run
|
||
|
assert:
|
||
|
that:
|
||
|
- "enable_in_check_mode_result.changed == true"
|
||
|
|
||
11 years ago
|
- name: enable the ansible test service
|
||
|
service: name=ansible_test enabled=yes
|
||
|
register: enable_result
|
||
|
|
||
8 years ago
|
- name: assert that the service was enabled and changes reported
|
||
11 years ago
|
assert:
|
||
|
that:
|
||
|
- "enable_result.enabled == true"
|
||
8 years ago
|
- "enable_result.changed == true"
|
||
11 years ago
|
|
||
|
- name: start the ansible test service
|
||
|
service: name=ansible_test state=started
|
||
|
register: start_result
|
||
|
|
||
|
- name: assert that the service was started
|
||
|
assert:
|
||
|
that:
|
||
|
- "start_result.state == 'started'"
|
||
|
|
||
|
- name: find the service with a pattern
|
||
|
service: name=ansible_test pattern="ansible_test_ser*" state=started
|
||
|
register: start2_result
|
||
8 years ago
|
# don't enable this check yet on systems with systemd because of https://github.com/ansible/ansible/issues/16694
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: assert that the service was started via the pattern
|
||
|
assert:
|
||
|
that:
|
||
|
- "start2_result.name == 'ansible_test'"
|
||
|
- "start2_result.state == 'started'"
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: restart the ansible test service
|
||
|
service: name=ansible_test state=restarted
|
||
|
register: restart_result
|
||
|
|
||
|
- name: assert that the service was restarted
|
||
|
assert:
|
||
|
that:
|
||
|
- "restart_result.state == 'started'"
|
||
|
|
||
|
- name: restart the ansible test service with a sleep
|
||
|
service: name=ansible_test state=restarted sleep=2
|
||
|
register: restart_sleep_result
|
||
8 years ago
|
# don't enable this check yet on systems with systemd because of https://github.com/ansible/ansible/issues/16694
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: assert that the service was restarted with a sleep
|
||
|
assert:
|
||
|
that:
|
||
|
- "restart_sleep_result.state == 'started'"
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: reload the ansible test service
|
||
|
service: name=ansible_test state=reloaded
|
||
|
register: reload_result
|
||
8 years ago
|
# don't do this on systems with systemd because it triggers error:
|
||
|
# Unable to reload service ansible_test: ansible_test.service is not active, cannot reload.
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: assert that the service was reloaded
|
||
|
assert:
|
||
|
that:
|
||
|
- "reload_result.state == 'started'"
|
||
9 years ago
|
when: service_type != "systemd"
|
||
11 years ago
|
|
||
|
- name: stop the ansible test service
|
||
|
service: name=ansible_test state=stopped
|
||
|
register: stop_result
|
||
|
|
||
|
- name: assert that the service was stopped
|
||
|
assert:
|
||
|
that:
|
||
|
- "stop_result.state == 'stopped'"
|
||
|
|
||
|
- name: disable the ansible test service
|
||
|
service: name=ansible_test enabled=no
|
||
|
register: disable_result
|
||
|
|
||
|
- name: assert that the service was disabled
|
||
|
assert:
|
||
|
that:
|
||
|
- "disable_result.enabled == false"
|
||
|
|
||
10 years ago
|
- name: try to enable a broken service
|
||
10 years ago
|
service: name=ansible_broken_test enabled=yes
|
||
10 years ago
|
register: broken_enable_result
|
||
|
ignore_errors: True
|
||
|
|
||
|
- name: assert that the broken test failed
|
||
|
assert:
|
||
|
that:
|
||
9 years ago
|
- "broken_enable_result|failed"
|
||
10 years ago
|
|
||
11 years ago
|
- name: remove the test daemon script
|
||
|
file: path=/usr/sbin/ansible_test_service state=absent
|
||
|
register: remove_result
|
||
|
|
||
|
- name: assert that the test daemon script was removed
|
||
|
assert:
|
||
|
that:
|
||
|
- "remove_result.path == '/usr/sbin/ansible_test_service'"
|
||
|
- "remove_result.state == 'absent'"
|
||
|
|
||
8 years ago
|
# cleaning up changes made by this playbook
|
||
11 years ago
|
- include: 'sysv_cleanup.yml'
|
||
8 years ago
|
when: service_type == "sysv"
|
||
11 years ago
|
- include: 'systemd_cleanup.yml'
|
||
8 years ago
|
when: service_type == "systemd"
|
||
11 years ago
|
- include: 'upstart_cleanup.yml'
|
||
8 years ago
|
when: service_type == "upstart"
|