标签:copy table 参考 hub localhost 机器 pac authorize 完成
首先ansible基于python2.X 环境
默认centos都已经安装好了python2环境
ansible可以通过源码,yum,pip等方式安装
本文采用pip安装方式
centos默认没有安装pip,这里我们要安装pip
参考文献:传送门
1 curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
2
3 python get-pip.py
4
5 [root@localhost ~]# pip -V
6 pip 19.0.2 from /usr/lib/python2.7/site-packages/pip (python 2.7)
yum install gcc glibc-devel zlib-devel rpm-build openssl-deve -y
yum install -y python-devel
[root@localhost ~]# pip install ansible
[root@localhost ~]# ansible --version
ansible 2.7.7
config file = None
configured module search path = [u‘/root/.ansible/plugins/modules‘, u‘/usr/share/ansible/plugins/modules‘]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
pip安装是没有config file文件的 我们可以将官网的默认文件上传到服务器
官方文档:传送门
mkdir /etc/ansible
touch /ect/ansible.cfg
创建后ansible会自动搜索,无需操作
[root@localhost ~]# ansible --version
ansible 2.7.7
config file = /etc/ansible/ansible.cfg
configured module search path = [u‘/root/.ansible/plugins/modules‘, u‘/usr/share/ansible/plugins/modules‘]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
到这里pip安装ansible就算完成了,接下来来实现一些具体的操作
主机说明
控制主机:10.0.15.59 用于控制其它机器的主机
管理主机:10.0.15.60 被控制的主机
管理主机:10.0.15.66 被控制的主机
A.在控制主机创建秘钥
ssh-keygen -t rsa
在root/.ssh目录下存在两个文件
id_rsa是私钥(不能外泄),id_rsa.pub这个是公钥
B.将控制主机的公钥远程传输到管理主机
ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.15.60
ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.15.66
输入密码后查看管理主机的.ssh目录下是否出现authorized_keys
C.测试免密是否成功
ssh root@10.0.15.60
ssh root@10.0.15.66
vim /etc/ansible/hosts
10.0.15.60
10.0.15.66
[root@localhost ~]# ansible all -m ping
10.0.15.66 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.0.15.60 | SUCCESS => {
"changed": false,
"ping": "pong"
}
磁盘检测
[root@localhost ~]# ansible all -m shell -a "df -hP|awk ‘NR>1 && int(\$5) ‘"
10.0.15.60 | CHANGED | rc=0 >>
/dev/mapper/centos-root 9.8G 5.0G 4.9G 51% /
tmpfs 488M 7.7M 480M 2% /run
/dev/mapper/centos-home 8.1G 2.6G 5.5G 32% /home
/dev/sda1 197M 120M 77M 61% /boot
10.0.15.66 | CHANGED | rc=0 >>
/dev/mapper/centos-root 17G 1.1G 16G 7% /
tmpfs 488M 7.7M 480M 2% /run
/dev/sda1 1014M 130M 885M 13% /boot
标签:copy table 参考 hub localhost 机器 pac authorize 完成
原文地址:https://www.cnblogs.com/charles1ee/p/10399892.html