This repository contains Ansible playbooks and roles for managing infrastructure components across multiple environments.
- Ubuntu Servers: Production and staging environments
- AWS EC2: Cloud instances
- Raspberry Pi: IoT and home automation devices
- macOS: Developer workstations (business and personal)
.
├── ansible.cfg # Ansible configuration file
├── hosts # Inventory file
├── site.yml # Main playbook
├── ubuntu.yml # Playbook for Ubuntu servers
├── ec2.yml # Playbook for EC2 instances
├── raspberrypi.yml # Playbook for Raspberry Pi
├── darwin-business.yml # Playbook for macOS business
├── darwin-personal.yml # Playbook for macOS personal
├── group_vars/ # Group variables
│ ├── all/ # Variables common to all hosts
│ ├── singleton_ext1/ # External singleton host variables
│ ├── singleton_int1/ # Internal singleton host 1 variables
│ └── singleton_int2/ # Internal singleton host 2 variables
└── roles/ # Ansible roles (services, applications, configuration management)
- Ansible 2.10 or later installed
- SSH access configured to target hosts
- 1Password CLI (
op) installed (version 2.18.0 or later) - direnv installed (optional but recommended)
This repository uses 1Password Service Accounts for authentication. Service Accounts allow automated access to secrets without interactive sign-in.
-
Install direnv:
# Ubuntu sudo apt install direnv # macOS brew install direnv
-
Add direnv hook to your shell (
~/.bashrcor~/.zshrc):eval "$(direnv hook bash)" # or zsh
-
Reload your shell and allow direnv:
source ~/.bashrc # or ~/.zshrc cd /path/to/ansible-playbooks direnv allow
The .envrc file contains the Service Account token and will be automatically loaded.
ansible-playbook site.yml# Ubuntu servers only
ansible-playbook ubuntu.yml
# EC2 instances only
ansible-playbook ec2.yml
# Raspberry Pi only
ansible-playbook raspberrypi.ymlansible-playbook site.yml --limit "fox.rewse.jp"# Ubuntu basic configuration and package installation only
ansible-playbook ubuntu.yml --tags ubuntu,package
# Docker related only
ansible-playbook site.yml --tags dockeransible-playbook site.yml --checkHosts are classified into the following groups:
darwin_business: Business macOS machinesdarwin_personal: Personal macOS machinesubuntu: Ubuntu serversec2: AWS EC2 instancesinternal: Internal network hostsraspberrypi: Raspberry Pi devicessingleton_ext1: External singleton hostsingleton_int1: Internal singleton host 1singleton_int2: Internal singleton host 2
Group-specific variables are placed in the group_vars/<group_name>/ directory:
vars: Regular variables and references to 1Password secrets usinglookup('pipe', 'op read ...')
Role-specific variables are defined in each role's vars/main.yml.
For efficient execution, tasks are tagged appropriately:
# Example: Ubuntu basic configuration only
ansible-playbook ubuntu.yml --tags ubuntu
# Example: Package installation only
ansible-playbook ubuntu.yml --tags package
# Example: Docker related only
ansible-playbook site.yml --tags docker- Verify before changes: Use the
--checkoption before applying to production - Utilize tags: Use tags to execute only necessary parts
- Use 1Password: Always store sensitive information in 1Password and reference via
lookup('pipe', 'op read ...') - Gradual application: Test large changes on specific hosts first
- Check logs: Review logs after execution to ensure no issues