https://github.com/tosin2013/molecule-podman-template
This template provides a foundation for creating Ansible roles specifically designed for Red Hat Enterprise Linux (RHEL) 9.5 environments. It includes the basic structure and testing capabilities using Molecule with Podman as the container engine.
https://github.com/tosin2013/molecule-podman-template
ansible kvm libvirt molecule rhel9
Last synced: about 2 months ago
JSON representation
This template provides a foundation for creating Ansible roles specifically designed for Red Hat Enterprise Linux (RHEL) 9.5 environments. It includes the basic structure and testing capabilities using Molecule with Podman as the container engine.
- Host: GitHub
- URL: https://github.com/tosin2013/molecule-podman-template
- Owner: tosin2013
- License: other
- Created: 2025-01-13T13:34:51.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-17T02:03:48.000Z (over 1 year ago)
- Last Synced: 2025-10-24T20:44:17.359Z (9 months ago)
- Topics: ansible, kvm, libvirt, molecule, rhel9
- Language: Shell
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
README
# Ansible Role Template for RHEL 9.5 with Podman Testing
[](LICENSE)
This template provides a foundation for creating Ansible roles specifically designed for Red Hat Enterprise Linux (RHEL) 9.5 environments. It includes the basic structure and testing capabilities using Molecule with Podman as the container engine.
## Table of Contents
- [Documentation](#documentation)
- [Architecture Overview](#architecture-overview)
- [Requirements](#requirements)
- [Getting Started](#getting-started)
- [Role Variables](#role-variables)
- [Dependencies](#dependencies)
- [Example Playbook](#example-playbook)
- [Testing](#testing)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)
- [Author Information](#author-information)
## Documentation
Comprehensive documentation is available in the [docs](docs/) directory:
- [Overview](docs/overview.md) - Project architecture and design
- [Usage](docs/usage.md) - Installation and usage instructions
- [Testing](docs/testing.md) - Detailed testing procedures
- [Troubleshooting](docs/troubleshooting.md) - Common issues and solutions
- [Contributing](docs/contributing.md) - Contribution guidelines
- [API Reference](docs/api.md) - Role parameters and interfaces
- [Changelog](docs/changelog.md) - Version history and release notes
## Architecture Overview
This role provides comprehensive management of libvirt virtualization on RHEL systems. Key features include:
- Virtual machine lifecycle management
- Network configuration for libvirt
- Storage pool management
- User access control
- Resource allocation management
The template follows standard Ansible role structure with additional Molecule testing configuration:
```
molecule-podman-template/
├── defaults/ # Default variables
│ └── main.yml
├── tasks/ # Main role tasks
│ └── main.yml
├── meta/ # Role metadata
│ └── main.yml
├── molecule/ # Molecule testing configuration
│ └── default/
│ ├── molecule.yml # Test environment config
│ ├── converge.yml # Test playbook
│ ├── verify.yml # Test cases
│ ├── prepare.yml # Test environment setup
│ └── Dockerfile # Test container image
└── tests/ # Integration tests
└── test.yml
```
The testing infrastructure uses:
- Podman as the container engine
- UBI 9 (Universal Base Image) as the base container
- Molecule for test orchestration
- Ansible for role execution and verification
## Requirements
* Ansible 2.9 or higher
* Python 3.9 or higher
* Access to a RHEL 9.5 target system
* Molecule
* Podman (preferred container engine for RHEL)
* UBI 9 container images access
## Converting the Template
1. Create your new role from this template:
```bash
cp -r molecule-podman-template your-role-name
cd your-role-name
```
2. Update the role metadata in `meta/main.yml`:
* Set the proper role name
* Update platform information to include RHEL 9.5
* Add relevant tags and dependencies
3. The molecule configuration in `molecule/default/molecule.yml` is already set up for RHEL 9.5 with Podman:
* Uses `registry.access.redhat.com/ubi9/ubi-init:latest`
* Configured with proper systemd support
* Includes necessary volume mounts and capabilities
4. Implement your role logic:
* Add tasks in `tasks/main.yml`
* Define variables in `defaults/main.yml`
* Create handlers in `handlers/main.yml` if needed
* Add templates in `templates/` if needed
5. Update testing:
* Modify `molecule/default/converge.yml` with your role
* Add tests to `molecule/default/verify.yml`
## Role Variables
Define your variables in `defaults/main.yml`. Document each variable here:
### Quick Reference Table
| Variable | Description | Default |
|----------|-------------|---------|
| libvirt_networks | List of virtual networks to configure | [] |
| libvirt_storage_pools | Storage pools configuration | [] |
| libvirt_vms | Virtual machines to manage | [] |
| libvirt_users | Users and permissions | [] |
| libvirt_tls | TLS configuration | false |
### Example Configuration
```yaml
libvirt_networks:
- name: internal
bridge: virbr1
ip: 192.168.100.1
netmask: 255.255.255.0
dhcp:
start: 192.168.100.100
end: 192.168.100.200
libvirt_storage_pools:
- name: default
type: dir
target: /var/lib/libvirt/images
libvirt_vms:
- name: test-vm
memory: 2048
vcpu: 2
disks:
- size: 20G
pool: default
networks:
- network: internal
### Common Variables
```yaml
# Target RHEL version
rhel_version: "9.5"
# System package configuration
system_packages:
- vim-enhanced
- git
- curl
# Service configuration
services:
- name: sshd
state: started
enabled: true
# Firewall configuration
firewall:
ports:
- 22
- 80
- 443
services:
- ssh
- http
- https
# User management
users:
- name: admin
groups: wheel
ssh_key: "ssh-rsa AAAAB3NzaC1yc2E..."
```
### Variable Usage Examples
1. Override default packages:
```yaml
system_packages:
- vim-enhanced
- git
- curl
- htop
- tmux
```
2. Configure additional services:
```yaml
services:
- name: sshd
state: started
enabled: true
- name: httpd
state: started
enabled: true
```
3. Add firewall rules:
```yaml
firewall:
ports:
- 22
- 80
- 443
- 8080
services:
- ssh
- http
- https
- cockpit
```
### Best Practices
- Use descriptive variable names
- Group related variables together
- Provide default values that work for most cases
- Document each variable with comments in defaults/main.yml
- Use YAML anchors and aliases for repeated structures
## Dependencies
List any role dependencies here. For example:
```yaml
dependencies: []
```
## Example Playbook
Here's how to use this role in your playbook:
```yaml
- hosts: rhel_servers
become: true
roles:
- role: your-role-name
vars:
rhel_version: "9.5"
```
## Testing
This template uses Molecule with Podman for testing. The configuration is already set up for RHEL 9.5 compatibility. For detailed testing procedures and examples, see the [Testing Documentation](docs/testing.md).
### Libvirt-Specific Testing Considerations
When testing libvirt functionality, additional configurations may be required:
1. Enable nested virtualization in your test environment
2. Configure proper SELinux contexts for libvirt
3. Set up required kernel modules
4. Configure proper user permissions
Example test configuration:
```yaml
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
platforms:
- name: libvirt-test
image: registry.access.redhat.com/ubi9/ubi-init:latest
privileged: true
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
command: /sbin/init
### Key Testing Features
- Podman-based test environments
- UBI 9 container images
- Systemd support in containers
- Comprehensive test verification
### Quick Start
```bash
# Run complete test sequence
molecule test
```
For more commands and detailed testing workflow, refer to the [Testing Documentation](docs/testing.md).
## Security Considerations
When using libvirt, consider the following security best practices:
- Use TLS for remote connections
- Implement proper SELinux policies
- Restrict user permissions using polkit
- Regularly update libvirt packages
- Monitor virtual machine activity
- Use secure storage backends
## Troubleshooting
For common issues and solutions, refer to the [Troubleshooting Documentation](docs/troubleshooting.md). This includes:
- Podman installation and configuration
- UBI image access
- SELinux context issues
- Systemd in containers
- Network configuration
- Molecule debugging
### Quick Diagnostics
```bash
# Check container status
podman ps -a
# View container logs
podman logs
# Inspect container configuration
podman inspect
```
## Contributing
We welcome contributions! Please read our [Contribution Guidelines](docs/contributing.md) for details on how to:
- Submit issues
- Create pull requests
- Follow coding standards
- Write documentation
## License
GNU General Public License v3.0
## Author Information
Tosin Akinosho