Python之——Ansible常用模块及API

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/79050132

一、远程命令模块

1、功能

模块包括command、script、shell,都可以实现远程shell命令运行。
command:作为Ansible的默认模块,可以运行远程权限范围所有的shell命令;
script: 在远程主机执行主控端存储的shell脚本文件,相当于scp+shell组合;
shell:执行远程主机的shell脚本文件

2、例子

ansible webservers -m command -a "free -m"
ansible wevservers -m script -a "/home/test.sh 12 34"
ansible wevservers -m shell -a "/home/test.sh"

二、copy模块

1、功能

实现主控端向目标主机拷贝文件,类似于scp功能。

2、例子

实现拷贝/home/test.sh文件之webservers组目标主机/tmp/目录下,并更新文件属于及权限(可以单独使用file模块实现权限的修改,格式为:path = /etc/foo.conf owner=foo group=foo mode = 0644)

# ansible webservers -m copy -a "src=/home/test.sh dest=/tmp/ owner=root group=root mode=0755"

三、stat模块

1、功能

获取远程文件状态信息,包括atime、ctime、mtime、md5、uid、gid等信息。

2、例子

ansible webservers -m stat -a "path=/etc/sysctl.conf"

四、get_ur模块

1、功能

实现在远程主机下载指定URL到本地,支持sha256sum文件校验。

2、例子

ansible webservers -m get_url -a "url=http://www.baidu.com dest=/tmp/index.html mode=0400 force=yes"

五、yum模块

1、功能

Linux平台软件包管理操作,常见有yum、apt管理方式

2、例子

ansible webservers -m apt -a "pkg=curl state=latest"
ansible webservers -m yum -a "name=curl state=latest"

六、cron模块

1、功能

远程主机crontab配置

2、例子

ansible webservers -m cron -a "name='check dirs' hour='5,2' hob='ls -alh > dev/null'"
效果如下:
# Ansible:check dirs
* 5,2 * * * ls -alh > dev/nullsalt '*' file.chown /etc/passwd root root

七、mount模块

1、功能

远程主机分区挂载

2、例子

ansible webservers -m mount -a "name=/mnt/data src=/dev/sd0 fstype=ext3 opts=ro state=present"

8、service模块

1、功能

远程主机系统服务管理。

2、例子

ansible webservers -m service -a "name=nginx state=stopped"
ansible webservers -m service -a "name=nginx state=restarted"
ansible webservers -m service -a "name=nginx state=reloaded"

九、sysctl模块

1、功能

远程Linux主机sysctl配置。

2、例子

sysctl: name=kernel.panic value=3 sysctl_file=/etc/sysctl.conf checks=before reload=yessalt '*' pkg.upgrade

十、user服务模块

1、功能

远程主机系统用户管理、

2、例子

#添加用户test
ansible webservers -m user -a "name=test comment='test'"
#删除用test
ansible webservers -m user -a "name=test state=absent remove=yes" 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰 河

可以吃鸡腿么?

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值