1.准备一个文件放入所有需要升级的服务器IP:ansible_failed_ip.txt
2.写一个用于在远程执行的脚本:update.sh
[[email protected] scripts]# cat update.sh #!/bin/bash tar xf /usr/local/src/Python-2.7.13.tgz -C /usr/local/src/ cd /usr/local/src/Python-2.7.13 && ./configure make && make install if [ -f /usr/bin/python ];then mv /usr/bin/python /usr/bin/python_old2 cp /usr/local/src/Python-2.7.13/python /usr/bin/python else cp /usr/local/src/Python-2.7.13/python /usr/bin/python fi
3.写一个脚本用于将需要传输的文件发送给远端服务器并执行远程脚本的脚本:update_python.sh
[[email protected] scripts]# cat update_python.sh #!/bin/bash for ip in `cat ansible_failed_ip.txt` do scp /usr/local/src/Python-2.7.13.tgz [email protected]$ip:/usr/local/src/ scp /server/scripts/update.sh [email protected]$ip:/tmp/update.sh ssh $ip "chmod +x /tmp/update.sh" done for ip in `cat ansible_failed_ip.txt` do ssh $ip ‘/tmp/update.sh‘ done
4.执行脚本:sh update_python.sh
时间: 2024-11-09 10:47:03