host-pattern 主机模式
    all 所有主机 ansible all-m ping
    通配符主机 ansible ser -m ping
    :或关系 ansible ‘webser:dbser’ -m ping
    &并且(需要引号) ansible ‘webser:&dbser’ -m ping
    !逻辑非 (在A不在B里面) ansible ‘A:!B’ -m ping
    综合逻辑 ansible ‘A:b:&C:!D’ -m ping 在a或者B里面 并且在C里面 不在D里面的主机
    正则表达式 ansible ‘~(web|db)ser’ -m ping

    执行过程:
    加载配置文件 - 加载对应模块 - 生成对应的python文件 - 将py文件拷贝到远程主机下 - 给py文件添加执行权限 - 执行并返回结果 - 删除临时文件
    模块
    command 远端执行命令 默认模块可以不用加 -m command (不支持 重定向 环境变量 这种情况使用shell)
    chdir 切换目录执行命令 ansible all -a ‘chdir /etc cat ./fstab’
    removes 不存在 不执行 ansible all -a ‘removes=/ cat /etc/fstab’ 存在/ 所以执行
    creates 存在 不执行 ansible all -a ‘creates=/ cat /etc/fstab’ 存在/ 不执行cat

    shell 远端执行命令
    ansible 192.168.1.10 -m shell -a “echo $HOSTNAME”

    script 脚本 传输脚本到远端 并且运行
    ansible 192.168.1.10 -m script -a ‘test.sh’

    copy 拷贝文件
    ansible 192.168.1.10 -m copy -a “src=~/selinux dest=/etc/selinux/config mode=0644 owner=root” // 拷贝文件 设置权限
    ansible 192.168.1.10 -m copy -a “content=’test content\n hello’ dest=/tmp/f1.txt” // 利用内容 直接生成文件

    Fetch **将远程主机文件 抓取到服务器端(不能操作目录)
    ansibel 192.168.1.10 -m fetch -a “src=/var/log/message dest=/data” 将远程主机mesage文件 抓取到本地 按host生成目录

    File 文件操作模块
    ansible 192.168.1.10 -m file -a “name=/data/app state=touch” 创建新文件夹 state(touch创建文件 directory创建目录 absent删除 link软连接 hard硬链接)

    Hostname 主机名操作模块
    ansible 192.168.1.10 -m hostname -a “name=host01”

    Cron 计划任务模块
    ansible all -m cron -a “minute=* weekday=1,3,5 job=’/bin/sh /root/test.sh’ name=runTest” // 开启定时任务
    ansible all -m cron -a “disabled=true job=’/bin/sh /root/test.sh’ name=runTest” // 禁用定时任务 disabled=no 启动
    ansible all -m cron -a “disabled=true job=’/bin/sh /root/test.sh’ name=runTest state=absent” // 删除定时任务

    Yum yum包管理操作模块
    ansible all -m yum -a “name=httpd,vsftpd state=latest” // 安装
    ansible all -m yum -a “name=httpd,vsftpd state=absent” // 卸载
    ansible all -m yum -a “name=/data/xx.rpm disable_gpg_check=yes” // 安装本地rpm包 需要rpm包在远程主机

    Service 服务器管理模块
    ansible all -m service -a “name=httpd state=started enabled=yes” // 开启远端机器服务 并且设置开机启动

    User 用户管理模块
    ansible all -m user -a “name=nobody shell=/sbin/nologin system=yes home=/var/nobody groups=root,bin uid=10080 conmment=’web server’”
    ansible all -m user -a “name=nobody state=absent remove=yes”

    Group 用户组管理模块