Add README.md file

This commit is contained in:
Michael Reber 2024-07-02 16:12:42 +02:00
parent 9ea0a8bd67
commit 484c3429d3
2 changed files with 127 additions and 1 deletions

126
README.md Normal file
View File

@ -0,0 +1,126 @@
# Ansible Handler
This project contains an Ansible playbook and a handler script to update servers to the latest patch level, check if a reboot is required, and manage the reboot process. The script and playbook handle both RPM-based (e.g., RedHat, CentOS, Rocky Linux) and Debian-based (e.g., Debian, Ubuntu) systems. Additionally, the playbook prints the uptime of each server at the end.
## Files
- `patch_servers.yml`: Ansible playbook to update servers, check for required reboots, manage reboots, and print uptime.
- `ansible_handler`: Shell script to handle various Ansible operations.
- `hosts`: Ansible inventory file listing servers and groups.
- `ansible.cfg`: Ansible configuration file.
## Prerequisites
- Ansible installed on the control node.
- SSH access to all servers with key-based authentication.
## Inventory File
The `hosts` inventory file should contain your servers grouped accordingly. Example:
```ini
[all]
server1
server2
server3
[proxy]
proxy1
proxy2
[apache]
apache1
apache2
```
## Configuration File
The `ansible.cfg` file should be configured to use your inventory file and SSH private key. Example:
```ini
[defaults]
inventory = hosts
remote_user = your_user
private_key_file = /path/to/your/private_key
host_key_checking = False
```
## Handler Script
The `ansible_handler` script provides a command-line interface for various operations.
### Usage
```bash
./ansible_handler {--update {--all|--group <group>|--list}|--list|--check <package>}
```
### Options
- `--update --all`: Update all servers in the inventory.
- `--update --group <group>`: Update servers in the specified group.
- `--update --list`: List all available updates.
- `--list`: List all servers in the inventory.
- `--check <package>`: Check the version of the specified package on all servers.
### Examples
- Update all servers:
```bash
./ansible_handler --update --all
```
- Update servers in the `proxy` group:
```bash
./ansible_handler --update --group proxy
```
- List all available updates:
```bash
./ansible_handler --update --list
```
- List all servers in the inventory:
```bash
./ansible_handler --list
```
- Check the version of the `openssh` package on all servers:
```bash
./ansible_handler --check openssh
```
## Ansible Playbook
The `patch_servers.yml` playbook performs the following actions:
1. Determines if the system is RPM or Debian based.
2. Updates the system packages.
3. Checks if a reboot is required.
4. Reboots the system if required, unless Elasticsearch is installed.
5. Notifies the user if a reboot is required but Elasticsearch is installed.
6. Prints the uptime of each server.
### Running the Playbook
To run the playbook manually:
```bash
ansible-playbook -i hosts patch_servers.yml
```
## Notes
- Modify the `ansible.cfg` and `hosts` files according to your environment.
## License
This project is licensed under the MIT License.
```
This `README.md` provides an overview of the project, instructions on configuring and using the handler script and playbook, and examples of common operations. Adjust the content as needed for your specific environment and requirements.

View File

@ -56,7 +56,7 @@ function print_help() {
echo " $0 --update --group proxy"
echo " $0 --update --list"
echo " $0 --list"
echo " $0 --check sshd"
echo " $0 --check openssh"
}
case "$1" in