【From】 https://blog.csdn.net/zhydream77/article/details/81223805web
ansible命令基础安全
• ansible <host-pattern> [options]
host-pattern 主机戒定义的分组
-M 指定模块路径
-m 使用模块,默认 command 模块
-a or --args 模块参数
-i inventory 文件路径,戒可执行脚本
-k 使用交亏式登彔密码
-e 定义变量
-v 详绅信息,-vvvv 开吭 debug 模式ssh
• 列出要执行的主机,不执行任何操做
ansible all --list-hosts.net
• 批量检测主机
ansible all -m pingdebug
• 批量执行命令
ansible all -m command -a 'id' -kblog
批量部署证书文件
• 每次交亏输入密码比较麻烦
• 密码写入配置文件安全性不好
• 不一样主机不一样密码,配置文件要上天
• 使用 key 方式认证,是一个不错的选择
• 给全部主机部署公钥部署
ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(</root/.ssh/authorized_keys)'" -k -vget
举例说明:io
批量检测主机
[root@ansible ~]# ansible web -m ping基础
批量执行命令
[root@ansible ~]# ansible all -m command -a 'uptime'
[root@ansible ~]# ansible web -m command -a 'uptime'
[root@ansible ~]# ansible web -m command -a 'uptime' -k
SSH password:
web1 | SUCCESS | rc=0 >>
14:37:12 up 5:12, 3 users, load average: 0.01, 0.03, 0.02
web2 | SUCCESS | rc=0 >>
14:37:12 up 5:03, 2 users, load average: 0.00, 0.01, 0.03
批量部署证书文件
[root@ansible ooxx]# ansible all -m authorized_key -a "user=root exclusive=true manage_dir=true key='$(</root/.ssh/id_rsa.pub)'" -k
注意: