add collections

This commit is contained in:
Gary Kwok
2024-02-01 11:40:42 +08:00
parent 0715d7c475
commit 7af4c56c96
3198 changed files with 455118 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2
destructive
needs/target/setup_epel
skip/osx
skip/macos
skip/freebsd
skip/aix
skip/python2.6 # python-daemon package used in integration tests requires >=2.7
skip/rhel # FIXME

View File

@@ -0,0 +1,9 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
process_root: /opt/httpd_echo
process_file: "{{ process_root }}/httpd_echo.py"
process_venv: "{{ process_root }}/venv"
process_run_cmd: "{{ process_venv }}/bin/python {{ process_file }}"

View File

@@ -0,0 +1,51 @@
# Copyright (c) 2020, Simon Kelly <simongdkelly@gmail.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import daemon
try:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
def write_to_output(stream, content):
stream.write(content)
except ImportError:
from http.server import BaseHTTPRequestHandler, HTTPServer
def write_to_output(stream, content):
stream.write(bytes(content, "utf-8"))
hostname = "localhost"
server_port = 8082
class EchoServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
write_to_output(self.wfile, self.path)
def run_webserver():
webServer = HTTPServer((hostname, server_port), EchoServer)
print("Server started http://%s:%s" % (hostname, server_port))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")
if __name__ == "__main__":
context = daemon.DaemonContext()
with context:
run_webserver()

View File

@@ -0,0 +1,8 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_pkg_mgr
- setup_remote_constraints

View File

@@ -0,0 +1,21 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "{{ reason }} ('up')"
command: "curl -sf http://localhost:8082/hello"
when: service_state == 'up'
register: curl_result
until: not curl_result.failed
retries: 5
delay: 1
- name: "{{ reason }} ('down')"
command: "curl -sf http://localhost:8082/hello"
register: curl_result
failed_when: curl_result == 0
when: service_state == 'down'
until: not curl_result.failed
retries: 5
delay: 1

View File

@@ -0,0 +1,99 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- name: Install EPEL repository (RHEL only)
include_role:
name: setup_epel
when:
- ansible_distribution in ['RedHat', 'CentOS']
- ansible_distribution_major_version is version('9', '<')
- name: create required directories
become: yes
file:
path: "{{ item }}"
state: directory
loop:
- /var/lib/monit
- /var/run/monit
- "{{ process_root }}"
- name: install monit
become: yes
package:
name: monit
state: present
- include_vars: '{{ item }}'
with_first_found:
- files:
- "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml"
- '{{ ansible_os_family }}.yml'
- 'defaults.yml'
- name: monit config
become: yes
template:
src: "monitrc.j2"
dest: "{{ monitrc }}"
- name: copy process file
become: yes
copy:
src: httpd_echo.py
dest: "{{ process_file }}"
- name: Install virtualenv on CentOS 8
package:
name: virtualenv
state: present
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '8'
- name: Install virtualenv on Arch Linux
pip:
name: virtualenv
state: present
when: ansible_os_family == 'Archlinux'
- name: install dependencies
pip:
name: "{{ item }}"
virtualenv: "{{ process_venv }}"
extra_args: "-c {{ remote_constraints }}"
loop:
- setuptools==44
- python-daemon
- name: restart monit
become: yes
service:
name: monit
state: restarted
- include_tasks: test.yml
always:
- name: stop monit
become: yes
service:
name: monit
state: stopped
- name: uninstall monit
become: yes
package:
name: monit
state: absent
- name: remove process files
file:
path: "{{ process_root }}"
state: absent

View File

@@ -0,0 +1,33 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# order is important
- import_tasks: test_reload_present.yml
- import_tasks: test_state.yml
vars:
state: stopped
initial_state: up
expected_state: down
- import_tasks: test_state.yml
vars:
state: started
initial_state: down
expected_state: up
- import_tasks: test_state.yml
vars:
state: unmonitored
initial_state: up
expected_state: down
- import_tasks: test_state.yml
vars:
state: monitored
initial_state: down
expected_state: up
- import_tasks: test_errors.yml

View File

@@ -0,0 +1,11 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Check an error occurs when wrong process name is used
monit:
name: missing
state: started
register: result
failed_when: result is not skip and (result is success or result is not failed)

View File

@@ -0,0 +1,65 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: reload monit when process is missing
monit:
name: httpd_echo
state: reloaded
register: result
- name: check that state is changed
assert:
that:
- result is success
- result is changed
- name: test process not present
monit:
name: httpd_echo
state: present
timeout: 5
register: result
failed_when: result is not skip and result is success
- name: test monitor missing process
monit:
name: httpd_echo
state: monitored
register: result
failed_when: result is not skip and result is success
- name: start process
shell: "{{ process_run_cmd }}"
- import_tasks: check_state.yml
vars:
reason: verify service running
service_state: "up"
- name: add process config
blockinfile:
path: "{{ monitrc }}"
block: |
check process httpd_echo with matching "httpd_echo"
start program = "{{ process_run_cmd }}"
stop program = "/bin/sh -c 'kill `pgrep -f httpd_echo`'"
if failed host localhost port 8082 then restart
- name: restart monit
service:
name: monit
state: restarted
- name: test process present again
monit:
name: httpd_echo
state: present
register: result
- name: check that state is unchanged
assert:
that:
- result is success
- result is not changed

View File

@@ -0,0 +1,38 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- import_tasks: check_state.yml
vars:
reason: verify initial service state
service_state: "{{ initial_state }}"
- name: change httpd_echo process state to {{ state }}
monit:
name: httpd_echo
state: "{{ state }}"
register: result
- name: check that state changed
assert:
that:
- result is success
- result is changed
- import_tasks: check_state.yml
vars:
reason: check service state after action
service_state: "{{ expected_state }}"
- name: try change state again to {{ state }}
monit:
name: httpd_echo
state: "{{ state }}"
register: result
- name: check that state is not changed
assert:
that:
- result is success
- result is not changed

View File

@@ -0,0 +1,19 @@
{#
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
#}
set daemon 2
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set pidfile /var/run/monit.pid
set eventqueue
basedir /var/lib/monit/events
slots 100
set httpd port 2812 and
use address localhost
allow localhost

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monitrc"

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monitrc"

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monit.conf"

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monitrc"

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monitrc"

View File

@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
monitrc: "/etc/monit/monitrc"