环境3台机器RHEL最小化安装
hostname file01 192.168.100.2
hostname file02 192.168.100.3
hostname file03 192.168.100.10
3台设备的系统环境配置
sed -i "s/\(HOSTNAME=\).*/\1file01/g" /etc/sysconfig/network cat >> /etc/hosts << EOF > 192.168.100.2 file01 file01 > 192.168.100.3 file02 file02 > 192.168.100.10 fiel03 file03 > EOF mount /dev/cdrom /media/cdrom/ cp /mnt/hgfs/D/ansible/* /usr/local/src/ cd /usr/local/src/
软件包安装
yum -y install gcc yum -y install zlib-devel yum -y install zlib-devel yum -y install expect yum -y install openssh-clients tar -zxvf Python-2.7.8.tgz tar -zxvf setuptools-7.0.tar.gz tar -zxvf pycrypto-2.6.1.tar.gz tar -zxvf yaml-0.1.5.tar.gz tar -zxvf PyYAML-3.11.tar.gz tar -zxvf MarkupSafe-0.9.3.tar.gz tar -zxvf Jinja2-2.7.3.tar.gz tar -zxvf ecdsa-0.11.tar.gz tar -zxvf paramiko-1.15.1.tar.gz tar -zxvf simplejson-3.6.5.tar.gz tar -zxvf ansible-1.7.2.tar.gz cd Python-2.7.8 ./configure --prefix=/usr/local/ make make install cd /usr/local/include/python2.7/ cp -a ./* /usr/local/include/ cd /usr/bin/ mv python python2.6 ln -s /usr/local/bin/python sed -i "s/\(\#\!\/usr\/bin\/\).*/\1python2.6/g" /usr/bin/yum cd /usr/local/src/setuptools-7.0 python setup.py install cd ../setuptools-7.0 python setup.py install cd ../pycrypto-2.6.1 python setup.py install cd ../yaml-0.1.5 ./configure --prefix=/usr/local/ make make install cd ../PyYAML-3.11 python setup.py install cd ../MarkupSafe-0.9.3 python setup.py install cd ../Jinja2-2.7.3 python setup.py install cd ../ecdsa-0.11 python setup.py install cd ../paramiko-1.15.1 python setup.py install cd ../simplejson-3.6.5 python setup.py install cd ../ansible-1.7.2 python setup.py install mkdir -p /etc/ansible/ cp /usr/local/src/ansible-1.7.2/examples/{ansible.cfg,hosts} /etc/ansible/
配置
cat > /etc/ansible/hosts << EOF [webservers] 192.168.100.3 192.168.100.10 [dbservers] 10.25.1.56 10.25.1.57 EOF
批量创建信任关系
cat >> host.txt << EOF > 192.168.100.3 > 192.168.100.10 >EOF ssh-keygen cat > xr.sh << eof #!/bin/bash cat host.txt | while read host do /usr/bin/expect << EOF spawn ssh-copy-id root@\$host expect { "yes/no" { send "yes\\r"; exp_continue} "*password:" { send "root-123\\r" } } expect eof EOF done eof chmod 755 xr.sh ./xr.sh
使用调试
ansible webservers -m setup ansible webservers -m ping
本文出自 “12092929” 博客,谢绝转载!
原文:http://12102929.blog.51cto.com/12092929/1975868