A macOS based EC2 relies on a AWS dedicated host
- In AWS ServicesQuota, check the quota for Dedicated Hosts (at least 1 mac1.metal)
- Python 3.x (for Ansible)
- install Terraform : https://www.terraform.io/
- install Ansible: https://www.ansible.com/
The key pair will be used to access the EC2 instance via SSH
ssh-keygen -P "" -t rsa -b 4096 -m pem -f key -C ""
It will generate a key file (private key) and a key.pub file (public key) in the root folder
(Within the terraform folder)
Initialize Terraform providers
terraform init
Deploy Terraform resources
terraform apply -var region=us-west-1 -var az=eu-west-1a
The result will be a running macOS based EC2 instance, within a VPC and accesible via SSH (port 22).
ℹ️ Wait until the instance status checks are fine (may take several minutes)
Test SSH connection
ssh -i ../key ec2-user@<Instance-Public-HostName>>
In case you want to remove all AWS assets
terraform destroy
(Within the ansible folder)
We are going to use the amazon.aws.aws_ec2 Ansible plugin, in order to build a dynamic Ansible inventory based on tag values (see aws_ec2.yaml file)
pip install boto3 botocore
Run the following command, and it should return your EC2 instance
ansible-inventory --list
ansible all --private-key ../key --user ec2-user --module-name ping
Execute Ansible playbook in order to set a password for user ec2-user and enable VNC
ansible-playbook --private-key ../key --user ec2-user --extra-vars "password=<password for ec2-user>" configure.yaml
As VNC data is not encrypted, we are going to use VNC through an SSH tunnel
ssh -L 5900:localhost:5900 -i ../key ec2-user@<Instance-Public-HostName>
Starting from now, with a VNC client, the EC2 instance can be reached from vnc://localhost:5900