commit 36294f1841aee5c2aeb4d95b0877878e03a49347 Author: 7Wate Date: Fri Sep 6 17:50:27 2024 +0800 chore: Add infrastructure automation templates for Ansible, Terraform, Chef, Puppet, and SaltStack diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..e69de29 diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..631b686 --- /dev/null +++ b/README.md @@ -0,0 +1,154 @@ +# DevOpsAutoInfraKit + +## 简介 + +DevOpsAutoInfraKit 整合了多个常见的基础设施自动化工具,包括 Ansible、Terraform、Chef、Puppet、SaltStack。该模板为不同环境下的基础设施自动化提供了标准化和模块化的管理方式,适合用于开发、测试和生产环境的基础设施即代码(IaC)管理。 + +## 目录结构 + +``` +├── ansible/ +│ ├── inventories +│ ├── playbooks +│ ├── roles +│ │ ├── app_server +│ │ ├── common +│ │ └── db_server_mysql +│ ├── vars +│ └── vault +├── terraform/ +│ ├── envs +│ └── modules +├── chef/ +│ ├── cookbooks +│ ├── roles +│ └── environments +├── puppet/ +│ ├── manifests +│ ├── modules +│ └── hieradata +├── saltstack/ +│ ├── states +│ ├── pillars +│ └── reactor +├── config/ +├── docs/ +├── logs/ +├── scripts/ +├── tests/ +│ ├── ansible +│ ├── terraform +│ ├── chef +│ ├── puppet +│ └── saltstack +├── README.md +├── requirements.txt +└── .gitignore +``` + +### 1. **Ansible** + +| **目录** | **说明** | +| ---------------------- | ------------------------------------------------------------ | +| `ansible/inventories/` | 包含不同环境的主机清单(如开发、生产、测试环境)。 | +| `ansible/playbooks/` | Ansible 剧本,用于定义自动化任务和操作。 | +| `ansible/roles/` | 模块化角色,用于按服务或组件分离配置,支持应用服务器、数据库服务器等。 | +| `ansible/vars/` | 变量文件,针对不同环境配置变量。 | +| `ansible/vault/` | 敏感信息存储,使用 Ansible Vault 加密。 | + +### 2. **Terraform** + +| **目录** | **说明** | +| -------------------- | ------------------------------------------------ | +| `terraform/envs/` | 不同环境(如开发、生产)的基础设施配置文件。 | +| `terraform/modules/` | 模块化的基础设施资源定义(如网络、计算、存储)。 | + +### 3. **Chef** + +| **目录** | **说明** | +| -------------------- | ----------------------------------------------------------- | +| `chef/cookbooks/` | Chef 的 cookbook,用于定义基础设施和应用配置。 | +| `chef/roles/` | Chef 中的角色定义,组合多个 cookbook 以管理完整的系统配置。 | +| `chef/environments/` | Chef 环境变量定义,不同环境的配置差异。 | + +### 4. **Puppet** + +| **目录** | **说明** | +| ------------------- | ------------------------------------------------------------ | +| `puppet/manifests/` | Puppet 配置文件,定义系统状态和资源。 | +| `puppet/modules/` | 模块化的资源管理,类似于 Chef 的 cookbooks 和 Ansible 的角色。 | +| `puppet/hieradata/` | 分层数据,用于不同环境的配置管理。 | + +### 5. **SaltStack** + +| **目录** | **说明** | +| -------------------- | ---------------------------------------------- | +| `saltstack/states/` | SaltStack 状态文件,定义系统状态和自动化任务。 | +| `saltstack/pillars/` | 类似于 Ansible 的 `vars`,用于存储环境变量。 | +| `saltstack/reactor/` | 事件驱动自动化,监听事件并自动触发状态变化。 | + +### 6. **通用目录** + +| **目录** | **说明** | +| ---------- | ------------------------------------------------------------ | +| `config/` | 用于存放全局配置文件或工具的额外配置。 | +| `docs/` | 项目文档目录,包含设计文档、API 文档等。 | +| `logs/` | 日志文件目录,用于存储自动化工具的运行日志。 | +| `scripts/` | 自动化脚本目录,包含 Python 或 Bash 脚本,用于触发部署、回滚或其他自动化流程。 | +| `tests/` | 测试目录,包含针对不同自动化工具的测试文件,如 Ansible、Terraform、Chef、Puppet 和 SaltStack 的单元测试或集成测试。 | + +## 如何使用 + +### 1. **克隆仓库** + +```shell +git clone https://your-git-server/your-repo.git +cd your-repo +``` + +### 2. **配置 Ansible** + +- 将主机清单文件放入 `ansible/inventories/environments.yml` 中。 +- 修改 `ansible/vars/` 目录下的变量文件,设置不同环境的变量。 + +### 3. **配置 Terraform** + +- 根据不同环境,修改 `terraform/envs/` 目录下的配置文件。 +- 使用 Terraform 初始化并应用配置: + +```shell +cd terraform +terraform init +terraform apply +``` + +### 4. **使用 Chef** + +- 在 `chef/cookbooks/` 目录中添加自定义的 cookbook。 +- 使用 `chef/roles/` 和 `chef/environments/` 目录管理角色和环境。 + +### 5. **配置 Puppet** + +- 在 `puppet/manifests/` 目录中定义 Puppet 配置,或添加新的模块到 `puppet/modules/`。 +- 在 `puppet/hieradata/` 中配置分层数据,管理环境变量。 + +### 6. **SaltStack 自动化** + +- 将系统状态定义在 `saltstack/states/` 中。 +- 使用 `saltstack/pillars/` 目录定义环境变量,并通过 `saltstack/reactor/` 实现事件驱动的自动化流程。 + +## 测试与调试 + +- 各工具的测试代码位于 `tests/` 目录下。针对不同的自动化工具(如 Ansible、Terraform、Chef、Puppet、SaltStack)分别提供单元测试和集成测试支持。 + +## 日志与故障排查 + +- 所有工具的运行日志会存储在 `logs/` 目录中,便于后续调试和故障排查。 + +## 贡献 + +如果你想为该项目做贡献,请查看 `CONTRIBUTING.md` 文档,了解如何提交 pull request。 + +## 许可证 + +该项目遵循 `LICENSE` 中规定的许可证协议。 \ No newline at end of file diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..e69de29 diff --git a/ansible/inventories/.keepgit b/ansible/inventories/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/inventories/environments.yml b/ansible/inventories/environments.yml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/playbooks/.keepgit b/ansible/playbooks/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/app_server/.keepgit b/ansible/roles/app_server/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/common/.keepgit b/ansible/roles/common/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/db_server_mysql/.keepgit b/ansible/roles/db_server_mysql/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/vars/.keepgit b/ansible/vars/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/ansible/vault/.keepgit b/ansible/vault/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/chef/cookbooks/.keepgit b/chef/cookbooks/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/chef/environments/.keepgit b/chef/environments/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/chef/roles/.keepgit b/chef/roles/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/config/.keepgit b/config/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/docs/.keepgit b/docs/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/logs/.keepgit b/logs/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/puppet/hieradata/.keepgit b/puppet/hieradata/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/puppet/manifests/.keepgit b/puppet/manifests/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/puppet/modules/.keepgit b/puppet/modules/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/saltstack/pillars/.keepgit b/saltstack/pillars/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/saltstack/reactor/.keepgit b/saltstack/reactor/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/saltstack/states/.keepgit b/saltstack/states/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/scripts/.keepgit b/scripts/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/terraform/envs/.keepgit b/terraform/envs/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/modules/.keepgit b/terraform/modules/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/.keepgit b/tests/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/ansible/.keepgit b/tests/ansible/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/chef/.keepgit b/tests/chef/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/puppet/.keepgit b/tests/puppet/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/saltstack/.keepgit b/tests/saltstack/.keepgit new file mode 100644 index 0000000..e69de29 diff --git a/tests/terraform/.keepgit b/tests/terraform/.keepgit new file mode 100644 index 0000000..e69de29