Ansible优化
1.开启SSH长连接
openssh版本高于5.6(multiplexing)
sh_args = -o ControlMaster=auto -o ControlPersist=5d
ControlPersist=5d 设置整改长连接保持5天,
2.开启pipelinling
目标机器需要编辑/etc/sudoers文件
编辑当前ansible用户的配置为requiretty
pipelinling = True
3.开启accelerate模式
使用python在被控机器上运行一个守护进程,然后Ansible通过整改守护进程监听的端口进行通信
注意:中控机和被控机需要安装pyhton-keyczar
[accelerate] accelerate_port = 5099 accelerate_timeout = 30 accelerate_connect_timeout = 5.0
4.设置facts缓存
Ansible收集每台主机的facts信息
关闭facts,可以直接设置为False,提高playbook效率
但是如果我们每次执行playbook时能收集facts,又想加速playbook效率,那么就需要配置facts缓存了
- 文件缓存
gathering = smart fact_caching_timeout = 86400 fact_caching = jsonfile fact_caching_connection = /dev/shm/ansible_fact_cache
- redis
gathering = smart fact_caching_timeout = 86400 fact_caching = redis
- memcached
gathering = smart fact_caching_timeout = 86400 fact_caching = memcached