You've already forked www.colben.cn
update
This commit is contained in:
@@ -6,51 +6,51 @@ tags: ["ansible"]
|
||||
categories: ["dev/ops"]
|
||||
---
|
||||
|
||||
# CentOS7 安装 ansible
|
||||
## CentOS7 安装 ansible
|
||||
```bash
|
||||
yum install ansible
|
||||
```
|
||||
|
||||
# 修改配置文件 /etc/ansible/ansible.conf
|
||||
## 修改配置文件 /etc/ansible/ansible.conf
|
||||
```
|
||||
# 取消 ssh key 验证
|
||||
## 取消 ssh key 验证
|
||||
host_key_checking = False
|
||||
# 改用 debug 输出模式
|
||||
## 改用 debug 输出模式
|
||||
stdout_callback = debug
|
||||
```
|
||||
|
||||
# 修改配置文件 hosts
|
||||
## 修改配置文件 hosts
|
||||
```
|
||||
# 增加 tomcat 服务器组
|
||||
## 增加 tomcat 服务器组
|
||||
[tomcat]
|
||||
tomcat101 ansible_ssh_host=192.168.1.101
|
||||
tomcat102 ansible_ssh_host=192.168.1.102
|
||||
tomcat103 ansible_ssh_host=192.168.1.103
|
||||
# 增加 mysql 服务器组
|
||||
## 增加 mysql 服务器组
|
||||
[mysql]
|
||||
mysql201 ansible_ssh_host=192.168.1.201 ansible_ssh_pass=111111
|
||||
mysql202 ansible_ssh_host=192.168.1.202
|
||||
mysql203 ansible_ssh_host=192.168.1.203
|
||||
# 全局设置全部服务器的默认设置
|
||||
## 全局设置全部服务器的默认设置
|
||||
[all:vars]
|
||||
ansible_ssh_port=22
|
||||
ansible_ssh_user=root
|
||||
ansible_ssh_pass=123456
|
||||
```
|
||||
|
||||
# authorized_key 模块
|
||||
## authorized_key 模块
|
||||
```bash
|
||||
# 分发密钥
|
||||
## 分发密钥
|
||||
ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'"
|
||||
```
|
||||
|
||||
# 简单使用
|
||||
## 简单使用
|
||||
- 批量设置主机名为资产名
|
||||
```bash
|
||||
ansible all -m shell -a 'hostnamectl set-hostname {{inventory_hostname}}'
|
||||
ansible all -m shell -a 'echo "{{ansible_ssh_host}} {{inventory_hostname}}" >> /etc/hosts'
|
||||
```
|
||||
|
||||
# ansible 常用 roles
|
||||
## ansible 常用 roles
|
||||
- [https://gitee.com/colben/ansible](https://gitee.com/colben/ansible)
|
||||
|
||||
|
Reference in New Issue
Block a user