423212 发表于 2017-9-7 11:12:33

自动化运维工具Ansible实战(四)常用模块

   Ansible模块按功能分为:云模块、集群模块、 命令模块、数据库模块、文件模块、资产模块、消息模块、监控模块、网络模块、通知模块、包管理模块、源码控制模块、系统模块、单元模块、web设施模块、windows模块 具体的可以参考官网(http://docs.ansible.com/ansible/latest/list_of_all_modules.html)。这里从官方分类的模块里选择最常用的一些模块进行介绍。1,ping模块。测试主机是否是通的

1
2
3
4
5
6
7
8
9
# ansible web1 -m ping
Server5 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
Server6 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}




2,远程命令模块

1
2
3
ansible webserver -m command -a "free -m"#远程命令。
ansible webserver -m script -a "/home/test.sh" #远程主机执行主控服务器ansible上的脚本
ansible webserver -m shell -a "/home/test.sh"   #执行远程主机上的脚本命令




3,setup模块。主要用于获取主机信息,在playbooks里经常会用到的一个参数,gather_facts就与该模块相关。setup模块下经常使用的一个参数是filter参数

1
2
3
ansible 10.212.52.252 -m setup -a 'filter=ansible_*_mb'   //查看主机内存信息
ansible 10.212.52.252 -m setup -a 'filter=ansible_eth'   //查看地接口为eth0-2的网卡信息
ansible all -m setup --tree /tmp/facts   //将所有主机的信息输入到/tmp/facts目录下,每台主机的信息输入到主机名文件中(/etc/ansible/hosts里的主机名)




4,stat模块。获取远程文件状态信息,包括atime、ctime、mtime、MD5、uid、gid等信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# ansible 192.168.180.5 -m stat -a "path=/etc/sysctl.conf
"
192.168.180.5 | SUCCESS => {
    "changed": false,
    "stat": {
      "atime": 1504513902.6297896,
      "checksum": "a27c7ce2e6002c37f3cb537ad997c6da7fd76480",
      "ctime": 1480926522.4591811,
      "dev": 64768,
      "executable": false,
      "exists": true,
      "gid": 0,
      "gr_name": "root",
      "inode": 393634,
      "isblk": false,
      "ischr": false,
      "isdir": false,
      "isfifo": false,
      "isgid": false,
      "islnk": false,
      "isreg": true,
      "issock": false,
      "isuid": false,
      "md5": "c97839af771c8447b9fc23090b4e8d0f",
      "mode": "0644",
      "mtime": 1361531931.0,
      "nlink": 1,
      "path": "/etc/sysctl.conf",
      "pw_name": "root",
      "readable": true,
      "rgrp": true,
      "roth": true,
      "rusr": true,
      "size": 1150,
      "uid": 0,
      "wgrp": false,
      "woth": false,
      "writeable": true,
      "wusr": true,
      "xgrp": false,
      "xoth": false,
      "xusr": false
    }
}




5,file模块。file模块主要用于远程主机上的文件操作,file模块包含如下选项:
force:需要在两种情况下强制创建软链接,一种是源文件不存在但之后会建立的情况下;另一种是目标软链接已存在,需要先取消之前的软链,然后创建新的软链,有两个选项:yes|no

[*]group:定义文件/目录的属组

[*]mode:定义文件/目录的权限

[*]owner:定义文件/目录的属主

[*]path:必选项,定义文件/目录的路径

[*]recurse:递归的设置文件的属性,只对目录有效

[*]src:要被链接的源文件的路径,只应用于state=link的情况

[*]dest:被链接到的路径,只应用于state=link的情况

[*]state:   

[*]directory:如果目录不存在,创建目录
[*]file:即使文件不存在,也不会被创建
[*]link:创建软链接
[*]hard:创建硬链接
[*]touch:如果文件不存在,则会创建一个新的文件,如果文件或目录已存在,则更新其最后修改时间
[*]absent:删除目录、文件或者取消链接文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# ansible 192.168.180.6 -m file -a "src=/etc/fstab dest=/
tmp/fstab state=link"                         ########在远程主机180.6上创建远程软连接
192.168.180.6 | SUCCESS => {
    "changed": true,
    "dest": "/tmp/fstab",
    "gid": 0,
    "group": "root",
    "mode": "0777",
    "owner": "root",
    "size": 10,
    "src": "/etc/fstab",
    "state": "link",
    "uid": 0
}
# ansible 192.168.180.6 -m file -a "path=/tmp/test state=
touch"                                 ############在远程主机180.6上创建test文件
192.168.180.6 | SUCCESS => {
    "changed": true,
    "dest": "/tmp/test",
    "gid": 0,
    "group": "root",
    "mode": "0644",
    "owner": "root",
    "size": 5,
    "state": "file",
    "uid": 0
}
# ansible 192.168.180.6 -m file -a "path=/tmp/test state=
absent"                              #############在远程主机删除文件
192.168.180.6 | SUCCESS => {
    "changed": true,
    "path": "/tmp/test",
    "state": "absent"
}
# ansible 192.168.180.6 -m file -a "path=/tmp/fstab state
=absent"                                          #############在远程主机删除fstab软连接
192.168.180.6 | SUCCESS => {
    "changed": true,
    "path": "/tmp/fstab",
    "state": "absent"
}




6,copy模块。实现复制文件到远程主机,copy模块包含如下选项:

[*]backup:在覆盖之前将原文件备份,备份文件包含时间信息。有两个选项:yes|no

[*]content:用于替代"src",可以直接设定指定文件的值

[*]dest:必选项。要将源文件复制到的远程主机的绝对路径,如果源文件是一个目录,那么该路径也必须是个目录

[*]directory_mode:递归的设定目录的权限,默认为系统默认权限

[*]force:如果目标主机包含该文件,但内容不同,如果设置为yes,则强制覆盖,如果为no,则只有当目标主机的目标位置不存在该文件时,才复制。默认为yes

[*]others:所有的file模块里的选项都可以在这里使用

[*]src:要复制到远程主机的文件在本地的地址,可以是绝对路径,也可以是相对路径。如果路径是一个目录,它将递归复制。在这种情况下,如果路径使用"/"来结尾,则只复制目录里的内容,如果没有使用"/"来结尾,则包含目录在内的整个内容全部复制,类似于rsync。

以下的例子试下拷贝/etc/ansible/script.sh文件到主机组web1所有的主机/tmp下并更新文件属主和权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# ansible web1 -m copy -a "src=/etc/ansible/script.sh des
t=/tmp/ owner=appuser group=appuser mode=0755"      ###复制本地脚本到远程主机server6下并定义用户和组以及权限755
Server6 | SUCCESS => {
    "changed": true,
    "checksum": "18ca258e92141948010f2e0896cf655cdb945a1d",
    "dest": "/tmp/script.sh",
    "gid": 500,
    "group": "appuser",
    "md5sum": "d5e15b2da056fdd7b7ba30100035de2e",
    "mode": "0755",
    "owner": "appuser",
    "size": 30,
    "src": "/root/.ansible/tmp/ansible-tmp-1504517543.07-102988847745614/source",
    "state": "file",
    "uid": 500
}




7,service模块。用于远程主机的服务管理。该模块包含如下选项:

[*]arguments:给命令行提供一些选项

[*]enabled:是否开机启动 yes|no

[*]name:必选项,服务名称

[*]pattern:定义一个模式,如果通过status指令来查看服务的状态时,没有响应,就会通过ps指令在进程中根据该模式进行查找,如果匹配到,则认为该服务依然在运行

[*]runlevel:运行级别

[*]sleep:如果执行了restarted,在则stop和start之间沉睡几秒钟
[*]state:对当前服务执行启动,停止、重启、重新加载等操作(started,stopped,restarted,reloaded)

1
2
3
4
5
6
7
8
####重启远程主机180.6的网卡服务
# ansible 192.168.180.6 -m service -a "name=network state
=restarted args=eth0"
192.168.180.6 | SUCCESS => {
    "changed": true,
    "name": "network",
    "state": "started"
}




8,cron模块。用于远程主机crontab配置,管理计划任务包含如下选项:

[*]backup:对远程主机上的原任务计划内容修改之前做备份

[*]cron_file:如果指定该选项,则用该文件替换远程主机上的cron.d目录下的用户的任务计划

[*]day:日(1-31,*,*/2,……)

[*]hour:小时(0-23,*,*/2,……)

[*]minute:分钟(0-59,*,*/2,……)

[*]month:月(1-12,*,*/2,……)

[*]weekday:周(0-7,*,……)

[*]job:要执行的任务,依赖于state=present

[*]name:该任务的描述

[*]special_time:指定什么时候执行,参数:reboot,yearly,annually,monthly,weekly,daily,hourly

[*]state:确认该任务计划是创建还是删除

[*]user:以哪个用户的身份执行


1
2
3
4
5
6
7
8
9
10
11
12
13
# ansible 192.168.180.6-m cron -a 'name="a job for rebo
ot" special_time=reboot job="/some/job.sh"'
192.168.180.6 | SUCCESS => {
    "changed": true,
    "envs": [],
    "jobs": [
      "a job for reboot"
    ]
}
##########客户端
-bash-4.1# crontab -l
#Ansible: a job for reboot
@reboot /some/job.sh




9,yum模块。Linux平台软件包管理操作 常见的有yum apt 管理方式,其选项有:

[*]config_file:yum的配置文件

[*]disable_gpg_check:关闭gpg_check

[*]disablerepo:不启用某个源

[*]enablerepo:启用某个源

[*]name:要进行操作的软件包的名字,也可以传递一个url或者一个本地的rpm包的路径

[*]state:状态(present,absent,latest)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# ansible 192.168.180.6 -m yum -a "name=curl state=latest
"
192.168.180.6 | SUCCESS => {
    "changed": true,
    "msg": "",
    "rc": 0,
    "results": [
      "已加载插件:fastestmirror\n设置更新进程\nLoading mirror speeds from cached hostfile\n解决依赖关系\n--> 执行事务检查\n---> Package curl.x86_64 0:7.19.7-52.el6 will be 升级\n---> Package curl.x86_64 0:7.19.7-53.el6_9 will be an update\n--> 处理依赖关系 libcurl = 7.19.7-53.el6_9,它被软件包 curl-7.19.7-53.el6_9.x86_64 需要\n--> 执行事务检查\n---> Package libcurl.x86_64 0:7.19.7-52.el6 will be 升级\n---> Package libcurl.x86_64 0:7.19.7-53.el6_9 will be an update\n--> 完成依赖关系计算\n\n依赖关系解决\n\n================================================================================\n 软件包          架构         版本                      仓库             大小\n================================================================================\n正在升级:\n curl            x86_64         7.19.7-53.el6_9         updates         197 k\n为依赖而更新:\n libcurl         x86_64         7.19.7-53.el6_9         updates         169 k\n\n事务概要\n================================================================================\nUpgrade       2 Package(s)\n\n总下载量:367 k\n下载软件包:\n--------------------------------------------------------------------------------\n总计                                          3.1 MB/s | 367 kB   00:00   \n运行 rpm_check_debug \n执行事务测试\n事务测试成功\n执行事务\n\r正在升级   : libcurl-7.19.7-53.el6_9.x86_64                               1/4 \n\r正在升级   : curl-7.19.7-53.el6_9.x86_64                                  2/4 \n\r清理       : curl-7.19.7-52.el6.x86_64                                    3/4 \n\r清理       : libcurl-7.19.7-52.el6.x86_64                                 4/4 \n\rVerifying: libcurl-7.19.7-53.el6_9.x86_64                               1/4 \n\rVerifying: curl-7.19.7-53.el6_9.x86_64                                  2/4 \n\rVerifying: curl-7.19.7-52.el6.x86_64                                    3/4 \n\rVerifying: libcurl-7.19.7-52.el6.x86_64                                 4/4 \n\n更新完毕:\ncurl.x86_64 0:7.19.7-53.el6_9                                                 \n\n作为依赖被升级:\nlibcurl.x86_64 0:7.19.7-53.el6_9                                              \n\n完毕!\n"
    ]
}
#######远程客户端的主机180.6yum更新之前
-bash-4.1# rpm -qa|grep curl
python-pycurl-7.19.0-9.el6.x86_64
libcurl-7.19.7-52.el6.x86_64
curl-7.19.7-52.el6.x86_64
#######远程客户端的主机180.6yum更新之后
-bash-4.1# rpm -qa|grep curl
python-pycurl-7.19.0-9.el6.x86_64
libcurl-7.19.7-53.el6_9.x86_64
curl-7.19.7-53.el6_9.x86_64




10.user模块。实现远程主机系统用户管理。

[*]home:指定用户的家目录,需要与createhome配合使用
[*]groups:指定用户的属组
[*]uid:指定用的uid
[*]password:指定用户的密码
[*]name:指定用户名
[*]createhome:是否创建家目录 yes|no
[*]system:是否为系统用户
[*]remove:当state=absent时,remove=yes则表示连同家目录一起删除,等价于userdel -r
[*]state:是创建还是删除
[*]shell:指定用户的shell环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ansible 192.168.180.6 -m user -a 'name=www1 comment=lqb
uid=1001 group=root '               ###新建www1用户
192.168.180.6 | SUCCESS => {
    "changed": true,
    "comment": "lqb",
    "createhome": true,
    "group": 0,
    "home": "/home/www1",
    "name": "www1",
    "shell": "/bin/bash",
    "state": "present",
    "system": false,
    "uid": 1001
}
# ansible 192.168.180.6 -m user -a 'name=www1 state=absen
t remove=yes'                     ########删除www1用户
192.168.180.6 | SUCCESS => {
    "changed": true,
    "force": false,
    "name": "www1",
    "remove": true,
    "state": "absent"
}




11.rsynchronize模块。使用rsync同步文件,其参数如下:

[*]archive: 归档,相当于同时开启recursive(递归)、links、perms、times、owner、group、-D选项都为yes ,默认该项为开启

[*]checksum: 跳过检测sum值,默认关闭

[*]compress:是否开启压缩

[*]copy_links:复制链接文件,默认为no ,注意后面还有一个links参数

[*]delete: 删除不存在的文件,默认no

[*]dest:目录路径

[*]dest_port:默认目录主机上的端口 ,默认是22,走的ssh协议

[*]dirs:传速目录不进行递归,默认为no,即进行目录递归

[*]rsync_opts:rsync参数部分

[*]set_remote_user:主要用于/etc/ansible/hosts中定义或默认使用的用户与rsync使用的用户不同的情况

[*]mode: push或pull 模块,push模的话,一般用于从本机向远程主机上传文件,pull 模式用于从远程主机上取文件


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#############使用rsynchronize模块首先远程客户端要先按照rsync包才可以使用
# ansible 192.168.180.6 -a "yum install rsync -y"
192.168.180.6 | SUCCESS | rc=0 >>
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
解决依赖关系
--> 执行事务检查
---> Package rsync.x86_64 0:3.0.6-12.el6 will be 安装
--> 完成依赖关系计算
依赖关系解决
================================================================================
软件包          架构             版本                     仓库            大小
================================================================================
正在安装:
rsync         x86_64         3.0.6-12.el6             base         335 k
事务概要
================================================================================
Install       1 Package(s)
总下载量:335 k
Installed size: 682 k
下载软件包:
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装   : rsync-3.0.6-12.el6.x86_64                                    1/1
Verifying: rsync-3.0.6-12.el6.x86_64                                    1/1
已安装:
rsync.x86_64 0:3.0.6-12.el6                                                   
完毕!

############远程客户端安装好rsync包后就可以在ansible服务端使用rsync进行同步了
# ansible 192.168.180.6 -m synchronize -a 'src=/etc/ansib
le/conf/hosts dest=/tmp/ '
192.168.180.6 | SUCCESS => {
    "changed": true,
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -i /root/.ssh/id_rsa_web -S none -o StrictHostKeyChecking=no -o Port=22' --out-format='<<CHANGED>>%i %n%L' \"/etc/ansible/conf/hosts\" \"root@192.168.180.6:/tmp/\"",
    "msg": "<f+++++++++ hosts\n",
    "rc": 0,
    "stdout_lines": [
      "<f+++++++++ hosts"
    ]
}




12.mount模块。主要配置挂载点的。主要的参数如下:

[*]dump

[*]fstype:必选项,挂载文件的类型

[*]name:必选项,挂载点

[*]opts:传递给mount命令的参数

[*]src:必选项,要挂载的文件

[*]state:必选项

[*]present:只处理fstab中的配置

[*]absent:删除挂载点

[*]mounted:自动创建挂载点并挂载之

[*]umounted:卸载


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
###############把本地的磁盘挂载到远程主机180.6上
# ansible 192.168.180.6 -m mount -a 'name=/tmp/app src=/d
ev/sda2 fstype=ext4 state=mounted opts=rw'
192.168.180.6 | SUCCESS => {
    "changed": true,
    "dump": "0",
    "fstab": "/etc/fstab",
    "fstype": "ext4",
    "name": "/tmp/app",
    "opts": "rw",
    "passno": "0",
    "src": "/dev/sda2"
}
#############下面是查看远程主机是否挂载成功
# ansible 192.168.180.6 -a 'cat /etc/fstab'
192.168.180.6 | SUCCESS | rc=0 >>
#
# /etc/fstab
# Created by anaconda on Wed Jan 18 14:50:09 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=942820c4-9134-41da-9271-78ad0f8a33b2 /                     ext4    defaults      1 1
UUID=e5d84663-09d2-429f-9f90-43a37b1a84a7 /opt                  ext4    defaults      1 2
UUID=e9098124-206a-4116-a580-91d1d46fe8a9 swap                  swap    defaults      0 0
tmpfs                   /dev/shm                tmpfs   defaults      0 0
devpts                  /dev/pts                devptsgid=5,mode=6200 0
sysfs                   /sys                  sysfs   defaults      0 0
proc                  /proc                   proc    defaults      0 0
/dev/sda2 /tmp/app ext4 rw 0 0
# ansible 192.168.180.6 -a 'df -h'         
192.168.180.6 | SUCCESS | rc=0 >>
Filesystem      SizeUsed Avail Use% Mounted on
/dev/sda1      87G   12G   71G14% /
tmpfs         935M   0935M   0% /dev/shm
/dev/sda2       9.9G1.4G8.1G15% /opt
/dev/sda2       9.9G1.4G8.1G15% /tmp/app




13.get_url模块。该模块主要用于从http,ftp ,https等服务器上下载文件类似于wget。主要选项如下:

[*]sha256sum:下载完成后进行sha256 check;

[*]timeout:下载超时时间,默认10s

[*]url:下载的URL

[*]url_password、url_username:主要用于需要用户名密码进行验证的情况

[*]use_proxy:是事使用代理,代理需事先在环境变更中定义


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
##################从网站下载页面到/tmp/下
# ansible 192.168.180.6 -m get_url -a "url=http://www.guo
jinbao.com dest=/tmp/guojinbao mode=0440 force=yes"   
192.168.180.6 | SUCCESS => {
    "changed": true,
    "checksum_dest": null,
    "checksum_src": "75fa271ea83d05f2817027cf4009f9e9fda7ef88",
    "dest": "/tmp/guojinbao",
    "gid": 0,
    "group": "root",
    "md5sum": "e9ea1af241cf68289f3286b99af24baa",
    "mode": "0440",
    "msg": "OK (unknown bytes)",
    "owner": "root",
    "size": 38033,
    "src": "/tmp/tmp47gp_m",
    "state": "file",
    "uid": 0,
    "url": "http://www.guojinbao.com"
}
########远程查看下载目录下有没有刚才下载的文件
# ansible 192.168.180.6 -a 'ls -lh /tmp/'
192.168.180.6 | SUCCESS | rc=0 >>
总用量 104K
drwx------2 root    root    4.0K 9月   5 16:01 ansible_zwKwyh
drwxr-xr-x. 7 appuser appuser 4.0K 1月19 2017 app
-r--r-----1 root    root   38K 9月   5 16:01 guojinbao
-rw-r--r--1 root    root    1.5K 9月   4 14:25 hosts
-r--r-----1 root    root   38K 9月   5 15:59 index.html
drwxr-xr-x. 3 root    root    4.0K 9月   5 15:17 install
-rwxr-xr-x1 appuser appuser   30 9月   4 17:32 script.sh
-rwxr-xr-x1 root    root      26 9月   4 15:52 test.sh
-rw-------. 1 root    root       0 1月18 2017 yum.log




14.sysctl包管理模块。用于远程主机sysctl的配置。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# ansible-doc -s sysctl      ###########查看sysctl的使用说明
- name: Manage entries in sysctl.conf.
action: sysctl
      ignoreerrors         # Use this option to ignore errors about unknown
                               keys.
      name=                  # The dot-separated path (aka `key') specifying the                               sysctl variable.
      reload               # If `yes', performs a `/sbin/sysctl -p' if the
                               `sysctl_file' is
                               updated. If `no',
                               does not reload
                               `sysctl' even if
                               the `sysctl_file'
                               is updated.
      state                  # Whether the entry should be present or absent in
                               the sysctl file.
      sysctl_file            # Specifies the absolute path to `sysctl.conf', if
                               not `/etc/sysctl.c
                               onf'.
      sysctl_set             # Verify token value with the sysctl command and
                               set with -w if
                               necessary
      value                  # Desired value of the sysctl key.





1
2
3
4
5
# ansible 192.168.180.6 -m sysctl -a "name=kernel.panic v
alue=3 sysctl_file=/etc/sysctl.conf"
192.168.180.6 | SUCCESS => {
    "changed": true
}




15.unarchive模块。功能:解压缩,这个模块有两种用法:
1、将ansible主机上的压缩包在本地解压缩后传到远程主机上,这种情况下,copy=yes
2、将远程主机上的某个压缩包解压缩到指定路径下。这种情况下,需要设置copy=no
具体吃的参数如下:

[*]copy:在解压文件之前,是否先将文件复制到远程主机,默认为yes。若为no,则要求目标主机上压缩包必须存在。

[*]creates:指定一个文件名,当该文件存在时,则解压指令不执行

[*]dest:远程主机上的一个路径,即文件解压的路径

[*]grop:解压后的目录或文件的属组

[*]list_files:如果为yes,则会列出压缩包里的文件,默认为no,2.0版本新增的选项

[*]mode:解决后文件的权限

[*]src:如果copy为yes,则需要指定压缩文件的源路径

[*]owner:解压后文件或目录的属主


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ansible 192.168.180.6 -m unarchive -a "src=/tmp/install
/zabbix-3.0.4.tar.gz dest=/tmp/ mode=0755"
192.168.180.6 | SUCCESS => {
    "changed": true,
    "dest": "/tmp/",
    "extract_results": {
      "cmd": [
            "/bin/gtar",
            "--extract",
            "-C",
            "/tmp/",
            "-z",
            "-f",
            "/root/.ansible/tmp/ansible-tmp-1504599995.75-84735087578916/source"
      ],
      "err": "",
      "out": "",
      "rc": 0
    },
    "gid": 0,
    "group": "root",
    "handler": "TgzArchive",
    "mode": "01777",
    "owner": "root",
    "size": 4096,
    "src": "/root/.ansible/tmp/ansible-tmp-1504599995.75-84735087578916/source",
    "state": "directory",
    "uid": 0
}
########下面是查看路径下的zabbix解压包

# ansible 192.168.180.6 -a 'ls -alh /tmp'
192.168.180.6 | SUCCESS | rc=0 >>
总用量 120K
drwxrwxrwt.7 root    root    4.0K 9月   5 16:28 .
dr-xr-xr-x. 24 root    root    4.0K 9月   1 09:45 ..
drwx------   2 root    root    4.0K 9月   5 16:28 ansible_1zOyd2
drwxr-xr-x.7 appuser appuser 4.0K 1月19 2017 app
-r--r-----   1 root    root   38K 9月   5 16:01 guojinbao
-rw-r--r--   1 root    root    1.5K 9月   4 14:25 hosts
drwxrwxrwt   2 root    root    4.0K 9月   1 09:45 .ICE-unix
-r--r-----   1 root    root   38K 9月   5 15:59 index.html
drwxr-xr-x.3 root    root    4.0K 9月   5 15:17 install
-rwxr-xr-x   1 appuser appuser   30 9月   4 17:32 script.sh
-rwxr-xr-x   1 root    root      26 9月   4 15:52 test.sh
-rw-------.1 root    root       0 1月18 2017 yum.log
drwxr-xr-x13 www      1000 4.0K 7月22 2016 zabbix-3.0.4





总之,以上就是ansible常用的模块,如果还需要其他的模块的话可以查看下官方文档(http://docs.ansible.com/ansible/latest/list_of_all_modules.html)也可以通过命令来进行查看
1,查看所有的模块命令: ansible-doc-l
2,查看具体某个模块用法:ansible-doc -s MODULE_NAME

页: [1]
查看完整版本: 自动化运维工具Ansible实战(四)常用模块