## 设置ansible
关闭主机ssh known_hosts检查
配置文件:/etc/ansible/ansible.cfg
```
sed -i 's/#host_key_checking = False/host_key_checking = False/g' /etc/ansible/ansible.cfg
```
## 使用git 克隆ansible role
```bash
[root@node roles]# git clone https://github.com/kuailemy123/Ansible-roles.git /etc/ansible/roles/
```
## 添加主机清单
这里以192.168.77.130主机为例,并将其设为node2组内。
```
cat >> /etc/ansible/hosts <<EOF
[mongo]
172.16.108.100 ansible_ssh_pass=
172.16.108.101 ansible_ssh_pass=
172.16.108.102 ansible_ssh_pass=
EOF
```
## 编写playbook
文件路径:/etc/ansible/roles/python2.7.yml
```yml
---
- hosts: node2
roles:
- { role: python2.7, python_version: "2.7.14"}
```
## 执行playbook
```bash
[root@node ansible]# ansible-playbook python2.7.yml
```
## 查看主机是否安装了python2.7版本
使用ad-hoc方式查看
```bash
[root@node ansible]# ansible node2 -m shell -a 'python -V'
192.168.77.130 | SUCCESS | rc=0 >>
Python 2.7.12
```
在主机上查看
```bash
[root@node2 ~]# python -V
Python 2.7.12
```
## SSH
```
---
- hosts: mongo
roles:
- ssh-keys
```