1.no agent: 不需要在被管控主机上安装任何软件
2.no server: 无服务器端,使用时直接运行命令即可
3.modules in any languages:基于模块工作,可使用任意语言开发模块,
4.yaml,not code:使用yaml语言定制剧本playbook,
5.ssh by default:基于SSH工作
1、ping模块
检测被管理端是否在线
[iyunv@master ~]# ansible test -m ping ---->test是自己在 /etc/ansible/hosts定义的
2、command 模块
在被管理端执行命令
不支持重定向,管道
默认模块
[iyunv@master ~]# ansible test -m command -a 'uptime'
[iyunv@master ~]# ansible test -m command -a 'date'
[iyunv@master ~]# ansible test -m command -a 'touch /tmp/aa.txt'
参数:
chdir=<Directory>
[iyunv@master ~]# ansible test -m command -a "chdir=/tmp ls ./"
3、shell 模块
在被管理端执行命令
支持重定向,管道
[iyunv@master ~]# ansible test -m shell -a 'echo "hello ansible" > /tmp/bb.txt'
4.copy模块
拷贝ansible管理端的文件到远程主机的指定位置
常见参数有:
dest= 指明拷贝文件的目标目录位置,使用绝对路径,如果源是目录,则目标也要是目录,如果目标文件已存在,会覆盖原有内容
src=\'#\'" 指明本地路径下的某个文件,可以使用相对路径和绝对路径,支持直接指定目录,如果源是目录,则目标也要是目录
mode= 指明复制时,目标文件的权限
owner= 指明复制时,目标文件的属主
group= 指明复制时,目标文件的属组
content= 指明复制到目标主机上的内容,不能与src一起使用,相当于复制content指明的数据,到目标文件中
[iyunv@master ~]# ansible test -m copy -a "src=/etc/hosts dest=/tmp"
[iyunv@master ~]# ansible test -m copy -a "src=/etc/passwd dest=/tmp mode=600owner=nobody group=nobody"
安装软件包:
[iyunv@master ~]# ansible test -m yum -a 'name=httpd state=present'
10、service模块
用来管理远程主机上的服务的模块
常见参数有:
name= 被管理的服务名称(/etc/init.d)
state=started|stopped|restarted 表示启动或关闭或重启
enabled=yes|no 表示要不要设定该服务开机自启动
runlevel= 如果设定了enabled开机自动启动,则要定义在哪些运行级别下自动启动
[iyunv@master ~]# ansible test -m service -a 'name=nginx state=started'
11. uri模块
如果远端是web服务器,可以利用ansible直接请求某个网页
常见参数有:
url= 指明请求的url的路径,如:
user= 如果请求的url需要认证,则认证的用户名是什么
password= 如果请求的url需要认证,则认证的密码是什么
method= 指明请求的方法,如GET、POST, PUT, DELETE, HEAD
[iyunv@master ~]# ansible test -m uri -a 'url=http://192.168.87.102/index.html'
12.group模块
用来添加或删除远端主机的用户组
常见参数有:
name= 被管理的组名
state=present|absent 是添加还是删除,不指名默认为添加
gid= 指明GID
system=yes|no 是否为系统组
[iyunv@master ~]# ansible test -m group -a 'name=hr gid=2000 state=present'