A comprehensive collection of Ansible roles for managing Lenovo XClarity BMC controllers via Redfish API. This project provides modular, reusable roles for power management, user management, and common BMC operations.
This project has been restructured into modular Ansible roles for better maintainability and reusability:
roles/
├── lenovo_xclarity_common/ # Common BMC connectivity and validation
├── lenovo_xclarity_power/ # Power management and PXE boot
└── lenovo_xclarity_user/ # User account management
lenovo_xclarity_power_playbook.yml- Power management operationslenovo_xclarity_user_playbook.yml- User management operationslenovo_xclarity_combined_playbook.yml- Combined operations playbook
- Power Control: Power on, power off (graceful/forced), reset, and status checking
- PXE Boot Configuration: One-time PXE boot setup with automatic system reset
- Smart Monitoring: Active power state monitoring until desired state is reached
- Intelligent Validation: Graceful exits and validation for invalid operations
- User Operations: Create, update, delete, and query user accounts
- Password Validation: Comprehensive password complexity checking
- Role Management: Support for Administrator, Operator, ReadOnly, and PowerUser roles
- Custom Roles: PowerUser role with specific console and power privileges
- BMC Connectivity: Automatic connection validation and service discovery
- Error Handling: Comprehensive error handling and graceful failures
- Flexible Configuration: Extensive variable customization
- Tagged Execution: Granular control with Ansible tags
- Ansible: Version 2.9 or higher
- Python: Version 3.6 or higher
- Network Access: HTTP/HTTPS connectivity to BMC controllers
- Credentials: Valid BMC username and password with appropriate privileges
- Operating System: Linux, macOS, or Windows (via WSL)
- Python: 3.6+ (3.8+ recommended)
- Ansible: 2.9+ (4.0+ recommended)
- Network: HTTPS access to BMC on port 443
| Component | Minimum | Recommended | Notes |
|---|---|---|---|
| Ansible | 2.9.0 | 4.0+ | Core functionality |
| Python | 3.6 | 3.8+ | Better performance |
git clone https://github.com/rut31337/lenovo-xclarity-ansible.git
cd lenovo-xclarity-ansibleEnsure Ansible 2.9+ is installed on your system.
# Check power status
ansible-playbook lenovo_xclarity_power_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e power_action=status
# Power on system
ansible-playbook lenovo_xclarity_power_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e power_action=on
# Configure PXE boot and reset
ansible-playbook lenovo_xclarity_power_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e enable_pxe_boot_and_reset=true# Create new user
ansible-playbook lenovo_xclarity_user_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e target_username=newuser \
-e target_password=NewPassword123! \
-e user_action=create \
-e user_role=Operator
# Update user password
ansible-playbook lenovo_xclarity_user_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e target_username=existinguser \
-e target_password=UpdatedPassword456! \
-e user_action=update_password# Power and user operations together
ansible-playbook lenovo_xclarity_combined_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
-e operation_type=both \
-e power_action=on \
-e target_username=newuser \
-e target_password=NewPassword123! \
-e user_action=createThis example demonstrates a common use case - creating a service account and configuring the server for PXE boot:
# Create a service user account and configure PXE boot with reset
ansible-playbook lenovo_xclarity_combined_playbook.yml \
-e bmc_hostname=169.60.175.224 \
-e bmc_username=root \
-e bmc_password=adminPassword123! \
-e operation_type=both \
-e target_username=serviceuser \
-e target_password=ServicePass123! \
-e user_action=create \
-e user_role=PowerUser \
-e enable_pxe_boot_and_reset=trueWhat this does:
- Connects to the BMC using admin credentials
- Creates a new user
serviceuserwith PowerUser role (if it doesn't exist) - Sets the password to
ServicePass123!with full validation - Configures one-time PXE boot override
- Resets the server to boot from network
Result: A new service account is created and the server reboots from PXE network, ready for OS deployment or maintenance.
---
- name: Custom BMC Management
hosts: localhost
roles:
- role: lenovo_xclarity_power
vars:
bmc_hostname: "192.168.1.100"
bmc_username: "admin"
bmc_password: "password123"
power_action: "on"
- role: lenovo_xclarity_user
vars:
bmc_hostname: "192.168.1.100"
bmc_username: "admin"
bmc_password: "password123"
target_username: "serviceuser"
target_password: "ServicePassword123!"
user_action: "create"
user_role: "Operator"| Variable | Required | Description | Default |
|---|---|---|---|
bmc_hostname |
Yes | BMC IP address or hostname | - |
bmc_username |
Yes | BMC username | - |
bmc_password |
Yes | BMC password | - |
bmc_validate_certs |
No | Validate SSL certificates | false |
bmc_timeout |
No | Connection timeout (seconds) | 30 |
| Variable | Required | Description | Default |
|---|---|---|---|
power_action |
No | Power action to perform | status |
enable_pxe_boot_and_reset |
No | Enable PXE boot with reset | false |
| Variable | Required | Description | Default |
|---|---|---|---|
target_username |
Yes | Target username | - |
target_password |
Yes* | Target password | - |
user_action |
No | User action to perform | status |
user_role |
No | User role to assign | ReadOnly |
*Required for create/update operations
# Run only connectivity tests
ansible-playbook lenovo_xclarity_power_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
--tags connectivity
# Run only power operations
ansible-playbook lenovo_xclarity_power_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
--tags power
# Skip validation
ansible-playbook lenovo_xclarity_user_playbook.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123 \
--skip-tags validation# Create encrypted credentials file
ansible-vault create vault.yml
# Content of vault.yml:
# bmc_password: your_secret_password
# target_password: new_user_password
# Use with playbook
ansible-playbook lenovo_xclarity_user_playbook.yml \
--ask-vault-pass \
-e @vault.yml \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e target_username=newuser \
-e user_action=createUser passwords must meet these requirements:
- Length: 10-32 characters
- Letters: At least one letter (A-Z or a-z)
- Numbers: At least one number (0-9)
- Complexity: At least 2 of: uppercase, lowercase, special characters
- Uniqueness: Cannot match username or its reverse
- Characters: No more than 2 consecutive identical characters
- Allowed Characters: A-Z, a-z, 0-9, and ~`!@#$%^&*()-+={}[]|:;"'<>,?/._
always: Critical tasks that always runconnectivity: BMC connection testsvalidation: Input validationinfo: Information display
power: Power management operationspxe: PXE boot configurationboot: Boot settings management
users: User account operationscreate: User creation operationsupdate_password: Password update operationsdelete: User deletion operationsstatus: User status displayrole_management: Role assignment operations
- Connection Timeout: Increase
bmc_timeoutvalue - SSL Certificate Errors: Set
bmc_validate_certs: false - Permission Denied: Ensure BMC credentials have appropriate privileges
- Password Validation Failures: Check password complexity requirements
Enable verbose output for troubleshooting:
ansible-playbook lenovo_xclarity_power_playbook.yml -vvv \
-e bmc_hostname=192.168.1.100 \
-e bmc_username=admin \
-e bmc_password=password123- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Create an issue on GitHub
- Check the role-specific README files for detailed documentation
- Review the troubleshooting section above
Created by prutledg for Lenovo XClarity BMC management automation.