Python之——Ansible常用模块及API
2018-01-13 11:15
555 查看
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/79050132
command:作为Ansible的默认模块,可以运行远程权限范围所有的shell命令;
script: 在远程主机执行主控端存储的shell脚本文件,相当于scp+shell组合;
shell:执行远程主机的shell脚本文件
一、远程命令模块
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"
相关文章推荐
- Python ansible常用模块
- Ansible常用模块API调用
- Ansible常用模块及API
- Python: shutil模块 常用api速查表
- python常用模块os和sys
- python 学习笔记 13 -- 常用的时间模块之time
- ansible常用模块详解
- Python常用模块资料
- Python-常用的内置模块
- Python模块常用的几种安装方式 windows下xgboost安装 whl文件安装
- python常用模块大全
- Python itertools 模块 api
- Python3常用模块的安装
- 在Python常用模块I如何打开相关文件的方法
- Python常用模块re,collections,random
- python 常用的模块(collections)转
- python常用模块
- 常用的python模块及安装方法
- Python sqlite3 模块 API
- python常用模块详解