安装:
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'