远程主机执行命令
ansible ysj-app-all -m shell -a “crontab -l”
ansible ysj-app-all -m shell -a “/etc/init.d/crond restart”

从远程主机拉取文件
ansible ysj-01 -m fetch -a “src=/data/logs/twlogs/2019-05-22.tar.gz dest=/root/“

从远程主机拉取目录
ansible ysj-app-all -m synchronize -a “src=/data/logs/tlog/2019-05-25 dest=/root/tlog/{{inventoryhostname}}/ mode=pull”
ansible ysj-01 -m synchronize -a “src=/data/logs/twlogs/2019-05-22
{{ansible_ssh_host}} dest=/root/twlogs/{{inventory_hostname}}/ mode=pull”

单独更新一个文件
ansible ysj-app-all -m copy -a “src=./s_b_server_open_time.json dest=/data/ysj/gameserver/conf/jsonconf/“

热更新
ansible ysj-app-all -m copy -a “src=gameserver.tar.gz dest=/tmp/“
ansible ysj-app-all -m unarchive -a “remote_src=yes src=/tmp/gameserver.tar.gz dest=/data/ysj/“

文件内容修改
#regexp为要修改的源内容的正则匹配,line为修改后的内容
ansible all -m lineinfile -a “dest=/root/test.txt regexp=’bbb’ line=’bbbbbbb’”

在某一行前面插入一行
ansible all -m lineinfile -a “dest=/root/test.txt insertbefore=’aa(.*)’ line=’eeee’”

在某一行后面插入一行
ansible all -m lineinfile -a “dest=/root/test.txt insertafter=’aa(.*)’ line=’eeee’”

删除某一行
ansible all -m lineinfile -a “dest=/root/test.txt regexp=’aa(.*)’ state=absent”

末尾加入一行
ansible all -m lineinfile -a “dest=/root/test.txt line=’hehe’”

后置引用
ansible all -m lineinfile -a ‘dest=/etc/resolv.conf regexp=”search(.*)” line=”#search\1” backrefs=yes’
ansible ysj-app-all -m copy -a “src=/data/scripts/rsync_log.sh dest=/data/scripts/rsync_log.sh mode=0755”
ansible ysj-app-all -m copy -a “src=/data/scripts/clear_log.sh dest=/data/scripts/clear_log.sh mode=0755”

每天凌晨1点执行
ansible ysj-app-all -m cron -a “name=’rsync_log’ job=’/data/scripts/rsync_log.sh’ minute=00 hour=01 state=present”

每小时执行一次
ansible ysj-app-all -m cron -a “name=’clear_log’ job=’/data/scripts/clear_log.sh’ minute=00 state=present”
ansible txy-efun-ysj-core-00[123] -m synchronize -a “src=/data/logs/* dest=/root/wukang/ mode=pull”

拷贝shell
ansible ar -m copy -a “src=/data/files/auto_up_process.sh dest=/data/scripts/auto_up_process.sh mode=0755”

添加一个计划任务,每分钟执行一次
ansible ar -m cron -a “job=’/bin/bash /data/scripts/auto_up_process.sh >> /data/scripts/auto_up_process.sh.log 2>&1’ minute=*/1 state=present name=’每分钟自动拉起ar进程’”

删除计划任务
ansible ar -m cron -a “job=’/bin/bash /data/scripts/auto_up_process.sh >> /data/scripts/auto_up_process.sh.log 2>&1’ minute=*/1 state=absent name=’每分钟自动拉起ar进程’”

添加管理key
ansible xxx -m authorized_key -a “user=root state=present key=’{{ lookup(‘file’, ‘/etc/ansible/roles/init/files/sa_key.pub’) }}’”