From 36294f1841aee5c2aeb4d95b0877878e03a49347 Mon Sep 17 00:00:00 2001 From: 7Wate Date: Fri, 6 Sep 2024 17:50:27 +0800 Subject: [PATCH] chore: Add infrastructure automation templates for Ansible, Terraform, Chef, Puppet, and SaltStack --- .gitignore | 0 .gitlab-ci.yml | 0 Jenkinsfile | 0 README.md | 154 +++++++++++++++++++++++++ ansible/ansible.cfg | 0 ansible/inventories/.keepgit | 0 ansible/inventories/environments.yml | 0 ansible/playbooks/.keepgit | 0 ansible/roles/app_server/.keepgit | 0 ansible/roles/common/.keepgit | 0 ansible/roles/db_server_mysql/.keepgit | 0 ansible/vars/.keepgit | 0 ansible/vault/.keepgit | 0 chef/cookbooks/.keepgit | 0 chef/environments/.keepgit | 0 chef/roles/.keepgit | 0 config/.keepgit | 0 docs/.keepgit | 0 logs/.keepgit | 0 puppet/hieradata/.keepgit | 0 puppet/manifests/.keepgit | 0 puppet/modules/.keepgit | 0 requirements.txt | 0 saltstack/pillars/.keepgit | 0 saltstack/reactor/.keepgit | 0 saltstack/states/.keepgit | 0 scripts/.keepgit | 0 terraform/envs/.keepgit | 0 terraform/main.tf | 0 terraform/modules/.keepgit | 0 tests/.keepgit | 0 tests/ansible/.keepgit | 0 tests/chef/.keepgit | 0 tests/puppet/.keepgit | 0 tests/saltstack/.keepgit | 0 tests/terraform/.keepgit | 0 36 files changed, 154 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 Jenkinsfile create mode 100644 README.md create mode 100644 ansible/ansible.cfg create mode 100644 ansible/inventories/.keepgit create mode 100644 ansible/inventories/environments.yml create mode 100644 ansible/playbooks/.keepgit create mode 100644 ansible/roles/app_server/.keepgit create mode 100644 ansible/roles/common/.keepgit create mode 100644 ansible/roles/db_server_mysql/.keepgit create mode 100644 ansible/vars/.keepgit create mode 100644 ansible/vault/.keepgit create mode 100644 chef/cookbooks/.keepgit create mode 100644 chef/environments/.keepgit create mode 100644 chef/roles/.keepgit create mode 100644 config/.keepgit create mode 100644 docs/.keepgit create mode 100644 logs/.keepgit create mode 100644 puppet/hieradata/.keepgit create mode 100644 puppet/manifests/.keepgit create mode 100644 puppet/modules/.keepgit create mode 100644 requirements.txt create mode 100644 saltstack/pillars/.keepgit create mode 100644 saltstack/reactor/.keepgit create mode 100644 saltstack/states/.keepgit create mode 100644 scripts/.keepgit create mode 100644 terraform/envs/.keepgit create mode 100644 terraform/main.tf create mode 100644 terraform/modules/.keepgit create mode 100644 tests/.keepgit create mode 100644 tests/ansible/.keepgit create mode 100644 tests/chef/.keepgit create mode 100644 tests/puppet/.keepgit create mode 100644 tests/saltstack/.keepgit create mode 100644 tests/terraform/.keepgit 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