# ansible-bastion **Repository Path**: hulu20/ansible-bastion ## Basic Information - **Project Name**: ansible-bastion - **Description**: 快速搭建一个简易堡垒机服务器 - **Primary Language**: Shell - **License**: LGPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 3 - **Created**: 2020-07-14 - **Last Updated**: 2022-10-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 1, 已验证环境: ```shell Centos 7 ansible 2.9.10 # 需先安装ansible,并创建root公钥 # yum install epel-release ansible -y # ssh-keygen -t rsa -f ~/.ssh/id_rsa -N '' ``` 2, 关于hosts ```shell 2.1 按需修改hosts.ini 2.2 hosts.ini 第一行为ansible服务器,堡垒机管理服务器 2.2 addnew 为后期新加服务器 2.4 /etc/ansible/inventory/default-hosts.ini 为普通用户使用默认hosts模板, 按需修改 ``` 3, vars 变量定义, 可按需修改 ```shell group_vars/all.yml ``` 4, 实现功能 ```shell 4.1 批量同步堡垒机root用户key到服务器 -- 主要针对堡垒机root用户操作管理 4.2 批量同步堡垒机sudo管理用户key到服务器 4.3 堡垒机批量添加运维用户 -- 主要针对堡垒机运维用户调用对应控制端运维管理用户操作管理 4.4 堡垒机批量添加开发用户 -- 主要针对开发需要登入服务器查看日志,与运维用户做权限分离 4.5 快速搭建一个简易堡垒机服务器 ``` 5, 使用方法 ```shell ansible -i hosts.ini all -m shell -a "whoami" #如能正常线上root, 说明hosts.ini 配置没有问题,并有root权限 ansible-playbook -i hosts.ini start.yml ``` 6, 添加新服务器 ```shell 6.1 先添加hosts.ini addnew 6.2 ansible -i hosts.ini all -m shell -a "whoami" 6.3 ansible-playbook -i hosts.ini -l addnew start.yml -t addmanager ```