This repository contains an Ansible playbook to set up a macOS machine with various tools and configurations. It is designed to automate the installation of essential software and configurations for development environments.
- Prerequisites
- Run Ansible Playbook
- Install Python and Ansible on macOS
- Ansible Structure
- Roles
- Variables
- Ensure SSH key exists
ls ~/.ssh/id_*- If not
ssh-keygen
- If not
- SSH key for GitHub
- Create SSH key and add it to your GitHub account
- Add SSH key to your macOS keychain
eval "$(ssh-agent -s)" ssh-add ~/.ssh/<your-ssh-key>
- Python
- Create venv for Ansible
python3 -m venv ansiblesource ansible/bin/activate
- Ansible
python3 -m pip install pipxpipx install --include-deps ansible
- Install homebrew
Run the below command, and then enter your password when prompted.
ansible-playbook -i inventory playbooks/macos/main.yml --ask-become-passAnsible Structure
ansible/
group_vars/
all/
env_vars.yml
env_vars.local.yml
host_vars/
localhost/
env_vars.yml
inventory/
hosts
playbooks/
macos/
main.yml
roles/
aws_login/
main.yml
playbooks.yml
Click to expand for more details
Setting up my laptop for work took way too long, getting the right tools, logging into the correct systems, cloning the right repos, etc.
This repository contains an Ansible playbook to set up a macOS machine with various tools and configurations. It is designed to automate the installation of essential software and configurations for development environments.
What I do when you execute the main playbook:
- Install:
- VSCode
- dependencies like curl, unzip and python
packagingto allow for AWS install - AWS CLI
- Clone repositories defined in the
group_clone_reposvariable. - Fetch environment variables from AWS Secrets Manager and create
.envfiles defined in thegroup_clone_reposvariable. - Install Python packages using
pipenvornpmas specified in thegroup_clone_reposvariable. - Setup the local development environment,
npm iandpipenv install. - Install Postgres version defined in the
group_postgres_versionvariable. - Install docker
- Build and run Docker containers for the cloned repositories, using the commands specified in the
group_clone_reposvariable. - Make fixtures for the repositories, if specified in the
group_clone_reposvariable. - Install postman
Variables
Create variables in the group_vars/all/env_vars.yml. There's a file already in there called env_vars.example.yml which you can rename to env_vars.yml.
python_interpreter: ".../bin/python"
# Directory for all the repos.
group_develop_dir: ".../repos/location"
# If SSO is required, set to true.
group_aws_sso_login_required: true
# AWS SSO
group_aws_details:
region: eu-west-2
output: json
sso_start_url: https://d-9c6714caab.awsapps.com/start
sso_region: eu-west-2
sso_account_id: <sso_account_id>
sso_role_name: <sso_role_name>
ecr_login_url: <id>.dkr.ecr.<region>.amazonaws.com
# Default is `/tmp`, change if you want to use a different directory for temporary files.
override_executable_temp_dir: /tmp
# This is used to prefix the repo name when cloning repos.
group_repo_organization: <org or user>
group_clone_repos:
backend-repo-name:
service: "backend"
install_pipenv: true # If pipenv is used, and you want to install set to true.
pipenv_subdir: <sub_dir> # Specify the subdirectory of Pipfile if applicable.
env_secret: # Environment secret for the repo. Uses aws secretsmanager.
id: secret-id
file: "{{ [group_develop_dir, '.../.env'] | path_join }}"
load_fixtures: true
docker:
build_command: "make build"
up_command: "make up"
check_ports_before_fixtures:
- port: 8001 # web
- port: 5433 # db
frontend-repo-name:
service: "frontend"
install_method: "npm"
node_version: "20.18"
env_secret:
id: secret-id
file: "{{ [group_develop_dir, 'frontend-repo-name', '.env.local'] | path_join }}"
# Postgres
group_postgres_version: 14
# If repo node version not provided, use this as a fallback.
group_fallback_node_version: "18"Install Python and Ansible on macOS
- Create a Python virtual environment:
python3 -m venv ansible source ansible/bin/activate - Upgrade pip (recommended):
pip install --upgrade pip pip install pipx
- Install Ansible inside the virtual environment:
pipx install ansible