ansible 小试

安装:

pip install ansible

添加配置文件:

配置文件查找顺序
* ANSIBLE_CONFIG (环境变量)
* ansible.cfg (当前目录下)
* .ansible.cfg (用户家目录下)
* /etc/ansible/ansible.cfg
* -i filename (手动传入配置文件)
# ansible config file
[local]
127.0.0.1

运行:

#查看远程主机是否存活
ansible -i hosts all -m ping
# 手动输入ssh账号密码 需要安装 sshpass
sudo aptitude install sshpass
ansible -i hosts all -a 'uptime' -u username --ask-pass password
# 添加受信host方式直接运行
ssh-keygen -t rsa
cd ~/.ssh
cp id_rsa.pub authorized_keys
cd ..
ansible -i hosts all -a 'uptime'
-----------------------------------------------------
说明:
  a).代码仅供学习交流
  b).本文根据自身经验及网络总结所作,如有错误,谢谢指教
  c).转载请注明出处。
-----------------------------------------------------
原文地址:https://www.cnblogs.com/xqbumu/p/5394746.html