1、ansible all -k -m shell -a ‘hostname’
没有配置 ssh 公私钥时输入密码
配置后:ansible all -m shell -a ‘hostname’
3、ansible 配置变量
ansible_ssh_pass=’password’ #配置密码
[group]
host1
host2
[group:vars]
ansible_ssh_pass=’password’ #为组配置密码或者其他变量
4、配置 inventory 目录
编辑 cfg 文件,
/etc/ansible # cat ansible.cfg
[defaults]
host_key_checking = False
inventory = /etc/ansible/inventory
在/etc/ansible/inventory 目录下配置响应的文件
ansible all –list-hosts 检查机器列表正确
5、使用用户密码登录认证
编辑 host 文件,修改类似以下内容:
cat /etc/ansible/inventory/hosts
[test]
iZ28nwm86khZ
[test:vars]
ansible_ssh_user=my_webad
ansible_ssh_pass=’my_webad’
然后执行验证
ansible test -m command -a ‘id’ -o
6、复制文件
ansible webservers -m copy -a ‘src=/etc/hosts dest=/tmp/myhosts owner=root group=root mode=755 backup=yes’ -o
ansible webserver -m shell -a ‘md5sum /tmp/myhosts’ -o 检查生效
7、收集服务器配置信息
ansible webserver -m setup
8、安装 ansible-shell