Python之——Ansible常用模塊及API,pythonansibleapi
轉載請注明出處:http://blog.csdn.net/l1028386804/article/details/79050132
python爬蟲手機版下載、一、遠程命令模塊
1、功能
模塊包括command、script、shell,都可以實現遠程shell命令運行。
少兒python和成人python、command:作為Ansible的默認模塊,可以運行遠程權限范圍所有的shell命令;
script: 在遠程主機執行主控端存儲的shell腳本文件,相當于scp+shell組合;
shell:執行遠程主機的shell腳本文件
python電影天堂源碼?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"
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态