项目实战:自动化工作站
如果你需要频繁更换电脑或重装系统,手动配置环境(安装 Zsh, VS Code, Git, Docker…)将是极其枯燥的。本项目的目标是:一键部署。
1. 核心工具:Ansible
Ansible 是一个“无侵入”的自动化运维工具,非常适合个人工作站。
1.1 安装 Ansible
sudo apt install ansible1.2 编写 Playbook (setup.yml)
▶ 自动化安装与配置示例
- hosts: localhost
connection: local
tasks:
- name: 安装常用软件
apt:
name:
- zsh
- git
- docker.io
- htop
state: present
update_cache: yes
- name: 更改默认 Shell 为 Zsh
user:
name: susu
shell: /usr/bin/zsh
- name: 自动同步 Dotfiles
git:
repo: 'https://github.com/susu/dotfiles.git'
dest: /home/susu/.dotfiles2. 环境一致性:Dotfiles
将你的 .zshrc, .tmux.conf, .vimrc 等配置文件上传到 GitHub。
- 管理工具: 推荐使用 GNU Stow 建立软链接。
- 一键同步:
cd ~/.dotfiles stow zsh tmux vim
3. 容器化工作流
不要在主机上安装各种语言环境(Node.js 14, 16, 20…),使用 Dev Containers 或 Docker 镜像:
# 启动一个临时的 Python 环境
docker run -it --rm -v $(pwd):/app python:3.9 bash