This Ansible playbook automates the setup of a secure VPC environment, including SSH configuration, new user creation, and firewall rules.
- Ansible installed on your local machine
- Access to a VPC with root credentials
- Basic understanding of SSH key pairs
Generate a new SSH key pair for VPC access:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
The keys will be generated in your ~/.ssh
directory:
- Private key:
~/.ssh/id_rsa
- Public key:
~/.ssh/id_rsa.pub
Copy your public key to the VPC's authorized keys:
- Access your VPC using existing credentials
- Add the content of
id_rsa.pub
to~/.ssh/authorized_keys
on the VPC
Create a hosts file (hosts
) with your VPC details:
[vpc]
1.1.1.1 # Replace with your VPC's public IP
Note: If you modify the
vpc
group name, ensure you update the corresponding reference in./personalvpc.yml
under thehosts
property.
- Edit
./config.yml
to set your preferred VPC name - Create an encrypted vault file for sensitive information:
ansible-vault create secrets.yml
- Add the following information to your vault:
ansible_user: <vpc_root_user> ansible_ssh_private_key_file: <path_to_vpc_pvt_key> custom_user_password: <new_user_pwd> custom_user: <new_user_username>
Run the playbook with:
ansible-playbook vpc_playbook.yml --ask-vault-pass
Enter your vault password when prompted.
The playbook will:
- Set up SSH configuration
- Create a new user with sudo privileges
- Configure firewall rules
- Generate new SSH keys for the custom user
- Create a local directory containing the new SSH keys for future VPC access
After successful execution, you'll find a new directory on your local machine containing:
- Private and public SSH keys for the new user
- Connection details for accessing the VPC with the new credentials
- Keep your vault password secure
- Store the generated SSH private keys safely
- Never commit sensitive information to version control
- Regularly rotate SSH keys and passwords
If you encounter issues:
- Verify your VPC's IP address is correct in the hosts file
- Ensure root SSH access is working before running the playbook
- Check that all paths in
secrets.yml
are absolute paths - Verify your vault file is properly encrypted
To customize the setup further, you can modify:
config.yml
for VPC-specific settingspersonalvpc.yml
for playbook tasks and roles- Firewall rules in the respective task files
For support or contributions, please open an issue or pull request in the repository.