ansible批量修改内核

1.创建脚本

tee -a /tmp/ss.sh <<-'EOF'
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

A="net.ipv4.tcp_syncookies=1"
B="net.ipv4.tcp_tw_reuse=1"
C="net.ipv4.tcp_tw_recycle=1"
D="net.ipv4.tcp_fin_timeout=30"

function confadd(){
#判断有则不增加,无则增加
grep -cq  "$1" /etc/sysctl.conf
if [ "$?" -ne "0" ];then
        echo $1 >> /etc/sysctl.conf
        echo 增加$1
    else
         echo ok
fi
}

confadd $A
confadd $B
confadd $C
confadd $D
sysctl -p

2.拷贝脚本

ansible 192.168.96.* -m copy -a "src=/tmp/ss.sh dest=/tmp"

3.执行

ansible 192.168.96.* -m shell -a "sh /tmp/ss.sh"

4.删除脚本

ansible 192.168.96.* -m file -a 'path=/tmp/ss.sh state=absent'
THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录