copy
ansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/ mode=0600 owner=oldboy group=oldboy "

创建目录
ansible oldboy -m file -a "dest=/tmp/oldboy_dir state=directory"

创建文件
ansible oldboy -m file -a "dest=/tmp/oldboy_file state=touch"

创建软连接
ansible oldboy -m file -a "src=/tmp/oldboy_file dest=/tmp/oldboy_file_link state=link"

删除目录文件信息
state=absent 目录将被递归删除以及文件,而链接将被取消链接
ansible oldboy -m file -a "dest=/tmp/oldboy_dir state=absent"
ansible oldboy -m file -a "dest=/tmp/oldboy_file state=absent"

创建多级目录
ansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/01/0/0/0/0/0/0/0/"

从远程拉取文件
ansible oldboy -m fetch -a "dest=/tmp/backup src=/etc/hosts"
flat 参数,拉去的时候不创建目录(同名文件会覆盖)
ansible oldboy -m fetch -a "dest=/tmp/backup/ src=/etc/hosts flat=yes"

mount参数实例
挂载
ansible 172.16.1.8 -m mount -a "fstype=nfs opts=rw path=/mnt/ src=172.16.1.31:/data/ state=mounted"
卸载
ansible 172.16.1.8 -m mount -a "fstype=nfs opts=rw path=/mnt/ src=172.16.1.31:/data/ state=unmounted"

cron模块
添加定时任务
ansible oldboy -m cron -a "minute=0 hour=0 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' name=oldboy01"
删除定时任务
ansible oldboy -m cron -a "minute=00 hour=00 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' name=oldboy01
只用名字就可以删除
ansible oldboy -m cron -a "name=oldboy01 state=absent"
注释定时任务
ansible oldboy -m cron -a "name=oldboy01 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' disabled=yes"
取消注释
ansible oldboy -m cron -a "name=oldboy01 job='/bin/sh /server/scripts/hostname.sh &>/dev/null' disabled=no"

yum 模块
ansible oldboy -m yum -a "name=nmap state=installed"

service模块
ansible oldboy -m service -a "name=crond state=restarted"

hostname 修改主机名模块
ansible 172.16.1.8 -m hostname -a "name=web01"

selinux 管理模块
ansible 172.16.1.8 -m selinux -a "state=disabled"

get_url 模块 == 【wget】
ansible 172.16.1.8 -m get_url -a "url=http://lan.znix.top/RDPWrap-v1.6.1.zip dest=/tmp/"

sudo的使用

ansible omg -S -R root -m shell -a ""   --sudo -k -K --user=XXXX

ansible-playbook -C webservice.yml -s -U zhangjian -k -e "host=test user=zhangjian"