This project provides tools for deploying and securing virtual machines in IBM Cloud:
- Terraform for automated VM deployment in IBM Cloud
- Ansible for hardening the security of RHEL-based VMs and setting up users and tools
- IBM Cloud Account
- Link to IBM Cloud: https://cloud.ibm.com/
- Terraform
- Follow the official Terraform installation guide
- You'll need an IBM Cloud API key
- Ansible
More details can be found in the ansible/README.md.
python3 -m venv ansible-env
source ansible-env/bin/activate # On Windows: ansible-env\Scripts\activate
pip install ansible-builder ansible-navigator- Podman
- Required for building the Ansible execution environment
- Follow the official Podman installation guide
-
Set up your IBM Cloud API key:
export IC_API_KEY=your_api_key -
Initialize Terraform:
cd terraform terraform init -
Customize your deployment:
cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your preferred settings -
Deploy the VM:
terraform apply
The deployment process will:
- Check for and generate SSH keys if needed
- Deploy the VM in IBM Cloud
- Update the Ansible inventory with the new VM's IP address
- Run the Ansible playbook to secure and set up the VM
The secure-vm role applies security hardening to a RHEL-based VM or its derivatives (CentOS, Rocky, AlmaLinux, Fedora).
Features:
- Firewall configuration with custom ports
- SELinux configuration
- SSH hardening:
- Custom SSH port configuration
- Disable password authentication (key-based only)
- Disable root login
For more details, see the secure-vm README.
The setup-vm role sets up users and installs tools on a VM.
Features:
- Creates a configurable number of users with sequential naming
- SSH key pair generation for each user
- Installs a configurable set of tools
- Optional sudo access for users
For more details, see the setup-vm README.
When you run the playbook, the setup-vm role will create a keys/ directory in your project root and populate it with the generated SSH keys
Find the keys at:
./keys/user1_id_rsa
./keys/user1_id_rsa.pub
./keys/user2_id_rsa
./keys/user2_id_rsa.pub
...ssh -i keys/user1_id_rsa -p <ssh_port> user1@MyHostIPYou can customize the secure-vm role by modifying the following files:
ansible/roles/secure-vm/defaults/main.yml: Change default settings like SSH port and permitRootLoginansible/roles/secure-vm/vars/main.yml: Add additional firewall ports
You can customize the setup-vm role by modifying the following files:
ansible/roles/setup-vm/defaults/main.yml: Change user settings and default toolsansible/roles/setup-vm/vars/main.yml: Add additional tools to install
You can customize the Terraform deployment by modifying the following files:
terraform/terraform.tfvars: Set your preferred VM configurationterraform/variables.tf: Add or modify available variables