Python Linux系统管理与自动化运维之深入浅出Ansible(二),pythonansible


Ansible常见模块使用和案例实现
本节主要讲解Ansible 命令的使用 目前Ansible官方提供的模块已经超过950个,这里只列举其中常用的12个模块,学会了这十二个模块对Ansible的基本使用已经有了一个大概的了解,然后我们再通过Ansible帮助命令去查询我们需要的模块使用方法。

1.ping 网络测试命令

ansible test -m ping

2.command/shell/raw/script 远程命令模块

ansible test -a "hostname"
ansible test -m command -a 'hostname'
ansible test -m command -a '/sbin/shutdown -t now'
ansible test -m shell -a 'cat /etc/passwd |wc -l'
ansible test -m raw -a 'cat /etc/passwd |wc -l'
ansible test -m script -a "test.sh"

3.file 文件命令

ansible test -m file -a "src=/root/anan.txt dest=/root/anan.link mode=777 owner=anan state=link force=yes" #创建链接

4.copy 拷贝命令

ansible test -m copy -a "src=/etc/ansible/test/test1.md dest=/root/test.md owner=root group=anan owner=744 backup=yes

5.user/group 用户和用户组命令

ansible test -m user -a “name=anan1 createhome=yes shell=/bin/bash comment=’ananbackup’”

6.apt/yum 软件包管理命令

ansible test -m yum -a "name=httpd yum=present/lastest/absent #安装 检测最新版 卸载

7.get_url 获取网络内容命令

ansible test -m get_url -a "url='https://github.com/ananzhoujiaan/test2' dest=/root/"

8.unarchive 解压缩命令

9.git git使用命令

ansible test -m git -a "repo=https://github.com/ananzhoujiaan/test2.git dest=/root/testfile version=HEAD"

10.stat 获取远程服务器信息命令

ansible test -m stat -a "path=/root/test.md"

11.cron 定时任务

ansible test -m cron -a "backup=yes name='test cron' minute=*/2 hour=* job='ls /tmp >/dev/null' "


/2 * * * ls /tmp >/dev/null

12.service 服务管理命令

ansible test -m service -a "name=httpd state="started/stoped/restarted""


常见模块返回值含义

相关内容

    暂无相关文章