You've already forked www.colben.cn
1.3 KiB
1.3 KiB
title, date, lastmod, tags, categories
title | date | lastmod | tags | categories | ||
---|---|---|---|---|---|---|
Ansible | 2019-10-30T11:38:39+08:00 | 2019-10-30T11:38:39+08:00 |
|
|
CentOS7 安装 ansible
yum install ansible
修改配置文件 /etc/ansible/ansible.conf
## 取消 ssh key 验证
host_key_checking = False
## 改用 debug 输出模式
stdout_callback = debug
修改配置文件 hosts
## 增加 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]
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 模块
## 分发密钥
ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'"
简单使用
- 批量设置主机名为资产名
ansible all -m shell -a 'hostnamectl set-hostname {{inventory_hostname}}' ansible all -m shell -a 'echo "{{ansible_ssh_host}} {{inventory_hostname}}" >> /etc/hosts'