码迷,mamicode.com
首页 > 其他好文 > 详细

ansible点对点模块练习

时间:2018-05-07 19:55:02      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:ansible

ping模块

[root@S01 ~]# ansible all -m ping

192.168.137.129 | SUCCESS => {

    "changed": false, 

    "ping": "pong"

}


command 模块

[root@S01 ~]# ansible web -m command -a 'chdir=/tmp ls'

192.168.137.129 | SUCCESS | rc=0 >>

1.txt

ansible_Q70Y4Z


copy模块

[root@S01 ~]# ansible web -m copy -a "src=/shell/age.sh dest=/tmp"

192.168.137.129 | SUCCESS => {

    "changed": true, 

    "checksum": "d5bd635509e72249356b49592e0dce27cbef3651", 

    "dest": "/tmp/age.sh", 

    "gid": 0, 

    "group": "root", 

    "md5sum": "40e866633434127016bf49c968c4661f", 

    "mode": "0644", 

    "owner": "root", 

    "size": 75, 

    "src": "/root/.ansible/tmp/ansible-tmp-1525714889.35-154761909372133/source", 

    "state": "file", 

    "uid": 0

}


[root@S01 ~]# ansible web -m copy -a "content='hello' dest=/tmp/1.txt mode=222 backup=yes" (content 相当于src内容  mode:权限  backup:是否备份)

192.168.137.129 | SUCCESS => {

    "backup_file": "/tmp/1.txt.3534.2018-05-08@00:41:49~", 

    "changed": true, 

    "checksum": "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", 

    "dest": "/tmp/1.txt", 

    "gid": 0, 

    "group": "root", 

    "md5sum": "5d41402abc4b2a76b9719d911017c592", 

    "mode": "0222", 

    "owner": "root", 

    "size": 5, 

    "src": "/root/.ansible/tmp/ansible-tmp-1525715328.28-92472994702448/source", 

    "state": "file", 

    "uid": 0

}


file模块

设置文件属性

创建目录:-a "path= state=directory"



[root@S01 ~]# ansible web -m file -a "path=/tmp/yang state=directory"

192.168.137.129 | SUCCESS => {

    "changed": true, 

    "gid": 0, 

    "group": "root", 

    "mode": "0755", 

    "owner": "root", 

    "path": "/tmp/yang", 

    "size": 6, 

    "state": "directory", 

    "uid": 0

}


fetch模块


从远程某主机获取文件到本地

dest:用来存放文件的目录,例如存放目录为backup,源文件名称为/etc/profile

  在主机pythonserver中,那么保存为/backup/pythonserver/etc/profile

Src:在远程拉取的文件,并且必须是一个file,不能是目录

注意:从远程获取到本地的文件,会保存到以远程主机的IP 为名的目录中,且保存目录结构


分析:拉取远程的/tmp/2.txt 文件,保存到本地的/shell/ 目录下

[root@S01 ~]# ansible web -m fetch -a "src=/tmp/2.txt dest=/shell/"

192.168.137.129 | SUCCESS => {

    "changed": true, 

    "checksum": "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", 

    "dest": "/shell/192.168.137.129/tmp/2.txt", 

    "md5sum": "5d41402abc4b2a76b9719d911017c592", 

    "remote_checksum": "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d", 

    "remote_md5sum": null

}


cron模块

在远程主机上,定义每5分钟,清空一次防火墙


[root@S01 ~]# ansible web -m cron -a "name='clear the iptable' minute=*/5 job='/sbin/iptalbes -F'"

192.168.137.129 | SUCCESS => {

    "changed": true, 

    "envs": [], 

    "jobs": [

        "clear the iptable"

    ]

}

[root@S01 ~]# ansible web -m shell -a "crontab -l"

192.168.137.129 | SUCCESS | rc=0 >>

#Ansible: clear the iptable

*/5 * * * * /sbin/iptalbes -F



ansible点对点模块练习

标签:ansible

原文地址:http://blog.51cto.com/4259679/2113643

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!