1.关闭获取被控主机信息:在playbook中关闭即可,在大量的主机下,其效果明显
hosts: all
gather_facts: no
2.在不使用sudo的情况下开启pipeling,减少ansible没有传输时的连接数
修改ansible.cfg中pipelining=False改为True
3.controlpresist 持久化socket,一次验证,多次通信,被控主机的ssh版本需要时5.6以上
cat ~/.ssh/config
Host *
Compression yes
ServerAliveInterval 60
ServerAliveCountMax 5
ControlMaster auto
ControlPath~/.ssh/sockets/%r@%h-%p
ControlPersist 4h
4.优化常规配置
host_key_checking = False #关闭密码检查
remote_user = ane #指定连接到的ssh用户
deprecation_warnings = False #关闭一些告警
retry_files_enabled = False #关闭book产生的retry文件
ssh_args = -C -o ControlMaster=auto -o ControlPersist=5d #开启ssh长连接为5天 ,要求ssh为5.6版本,查看版本ssh -v