ansbile使用的中的一个小问题,更详细的信息可以参考 我的博客
ssh key提示处理
解决第一次连接的时候一般会提示输入yes 进行确认为将key字符串加入到 ~/.ssh/known_hosts 文件中,为避免该提示,可以修改ansible.cfg文件,增加如下配置:
host_key_checking = False
批量变更设置
ansible hosts文件配置如下
[n8]
192.168.6.205
192.168.6.206
10.125.40.[80:101]
[n8:vars]
ansible_ssh_user=zabbix
ansible_ssh_pass=Zbxpassword
上面有两个知识点: - 设定主机组后,可以对该主机组设定相同的变量,比如用户名、密码、端口等; - 连续的主机可以通过[n1:n2]这样的格式去表述。
su替换
[test01]
10.212.52.14 ansible_ssh_user=test ansible_ssh_pass=111111 ansible_su_pass=*I2145
10.212.52.16 ansible_ssh_user=test ansible_ssh_pass=xyz123 ansible_su_pass=mn1Pokm
10.212.52.252 ansible_ssh_user=amos ansible_ssh_pass=asdf ansible_su_pass=xyzp)
执行时使用如下命令:
ansible all -S -R root -m shell -a "uptime"