diff options
Diffstat (limited to '')
4 files changed, 123 insertions, 0 deletions
diff --git a/test/integration/targets/service_facts/tasks/main.yml b/test/integration/targets/service_facts/tasks/main.yml new file mode 100644 index 0000000..d2d6528 --- /dev/null +++ b/test/integration/targets/service_facts/tasks/main.yml @@ -0,0 +1,29 @@ +# Test playbook for the service_facts module +# Copyright: (c) 2017, Adam Miller <admiller@redhat.com> +# Copyright: (c) 2020, Abhijeet Kasurde <akasurde@redhat.com> +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: skip broken distros + meta: end_host + when: ansible_distribution == 'Alpine' + +- name: Gather service facts + service_facts: + +- name: check for ansible_facts.services exists + assert: + that: ansible_facts.services is defined + +- name: Test disabled service facts (https://github.com/ansible/ansible/issues/69144) + block: + - name: display value of ansible_service_mgr + debug: + msg: 'ansible_service_mgr: {{ ansible_service_mgr }}' + + - name: setup test service script + include_tasks: 'systemd_setup.yml' + + - name: execute tests + import_tasks: tests.yml + + when: (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version is version('7', '>=')) or ansible_distribution == 'Fedora' or (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('15.04', '>=')) or (ansible_distribution == 'Debian' and ansible_distribution_version is version('8', '>=')) or ansible_os_family == 'Suse' diff --git a/test/integration/targets/service_facts/tasks/systemd_cleanup.yml b/test/integration/targets/service_facts/tasks/systemd_cleanup.yml new file mode 100644 index 0000000..b68530b --- /dev/null +++ b/test/integration/targets/service_facts/tasks/systemd_cleanup.yml @@ -0,0 +1,32 @@ +- name: remove the systemd unit file + file: + path: /usr/lib/systemd/system/ansible_test.service + state: absent + register: remove_systemd_result + +- name: assert that the systemd unit file was removed + assert: + that: + - "remove_systemd_result.path == '/usr/lib/systemd/system/ansible_test.service'" + - "remove_systemd_result.state == 'absent'" + +- name: remove python systemd test script file + file: + path: /usr/sbin/ansible_test_service + state: absent + register: remove_systemd_binary_result + +- name: assert that python systemd test script file was removed + assert: + that: + - "remove_systemd_binary_result.path == '/usr/sbin/ansible_test_service'" + - "remove_systemd_binary_result.state == 'absent'" + +- name: make sure systemd is reloaded + shell: systemctl daemon-reload + register: restart_systemd_result + +- name: assert that systemd was reloaded + assert: + that: + - "restart_systemd_result.rc == 0" diff --git a/test/integration/targets/service_facts/tasks/systemd_setup.yml b/test/integration/targets/service_facts/tasks/systemd_setup.yml new file mode 100644 index 0000000..85eeed0 --- /dev/null +++ b/test/integration/targets/service_facts/tasks/systemd_setup.yml @@ -0,0 +1,26 @@ +- name: install the test daemon script + copy: + src: ansible_test_service.py + dest: /usr/sbin/ansible_test_service + mode: '755' + +- name: rewrite shebang in the test daemon script + lineinfile: + path: /usr/sbin/ansible_test_service + line: "#!{{ ansible_python_interpreter | realpath }}" + insertbefore: BOF + firstmatch: yes + +- name: install the systemd unit file + copy: + src: ansible.systemd + dest: /etc/systemd/system/ansible_test.service + mode: '0644' + register: install_systemd_result + +- name: assert that the systemd unit file was installed + assert: + that: + - "install_systemd_result.dest == '/etc/systemd/system/ansible_test.service'" + - "install_systemd_result.state == 'file'" + - "install_systemd_result.mode == '0644'" diff --git a/test/integration/targets/service_facts/tasks/tests.yml b/test/integration/targets/service_facts/tasks/tests.yml new file mode 100644 index 0000000..495b71f --- /dev/null +++ b/test/integration/targets/service_facts/tasks/tests.yml @@ -0,0 +1,36 @@ +- name: start the ansible test service + service: + name: ansible_test + enabled: yes + state: started + register: enable_result + +- name: assert that the service was enabled and changes reported + assert: + that: + - "enable_result.enabled == true" + - "enable_result is changed" + +- name: disable the ansible test service + service: + name: ansible_test + state: stopped + enabled: no + register: start_result + +- name: assert that the service was stopped + assert: + that: + - "start_result.state == 'stopped'" + - "start_result is changed" + +- name: Populate service facts + service_facts: + +- name: get ansible_test service's state + debug: + var: services['ansible_test.service'].state + +- name: ansible_test service's running state should be \"inactive\" + assert: + that: "services['ansible_test.service'].state == 'inactive'" |