ansible命令基础:ansible <主机或定义的分组> [选项]
-M 指定模块路径
-m 使用模块,默认command模块
-a 模块参数
-i inventory文件路径或可执行脚本
-k 使用交互式登陆密码
-e 定义变量vim
-v 详细信息,-vvvv开启debug模式
[devops@server1 ansible]$ ansible test -a 'df -h'
server2 | CHANGED | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 17G 1.1G 16G 6% /
devtmpfs 486M 0 486M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 13M 484M 3% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 1014M 121M 894M 12% /boot
tmpfs 100M 0 100M 0% /run/user/0
tmpfs 100M 0 100M 0% /run/user/1001
ansible server1 -m setup #产看指定主机server1上的facts变量信息
ansible * -m setup #查看指定的所有主机上的facts变量信息
ansible-doc -l:列出有哪些可用的模块,按q退出
ansible-doc -l | wc -l:列出有多少个可用的模块
ansible-doc -l | grep user:列出与user有关的模块
ansible-doc user:查看user模块的帮助文档,按q退出。也可以在最后一行输入/passwd,来过滤与passwd有关的内容
ansible test -a 'df -h' 在test组执行df -h命令