一、命令模块
1.command模块
[root@m01 ~]
web01 | CHANGED | rc=0 >>
total used free shared buff/cache available
Mem: 972 128 479 7 364 658
Swap: 1023 0 1023
[root@m01 ~]
web01 | FAILED | rc=1 >>
|: Unknown host
ifconfig: `--help' gives usage information.non-zero return code
2.shell模块
[root@m01 ~]
web01 | CHANGED | rc=0 >>
total used free shared buff/cache available
Mem: 972 128 479 7 364 658
Swap: 1023 0 1023
[root@m01 ~]
web01 | CHANGED | rc=0 >>
10.0.0.7
3.scripts 模块
[root@m01 ~]
mkdir /dir
[root@m01 ~]
web02 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to web02 closed.\r\n",
"stderr_lines": [
"Shared connection to web02 closed."
],
"stdout": "",
"stdout_lines": []
}
web01 | CHANGED => {
"changed": true,
"rc": 0,
"stderr": "Shared connection to web01 closed.\r\n",
"stderr_lines": [
"Shared connection to web01 closed."
],
"stdout": "",
"stdout_lines": []
}
[root@m01 ~]
web01 | CHANGED | rc=0 >>
drwxr-xr-x. 2 root root 6 Dec 18 08:40 /dir
web02 | CHANGED | rc=0 >>
drwxr-xr-x 2 root root 6 Dec 18 08:40 /dir
二、软件管理模块
1.yum模块
[root@m01 ~]
EXAMPLES:
- name: install the latest version of Apache
yum:
name: httpd
state: latest
name:
httpd
file
http://nginx.org/...
state:
latest
absent
present
[root@m01 ~]
相当于在远程机器上执行:yum install -y httpd
[root@m01 ~]
相当于在远程机器上执行:yum localinstall -y /tmp/nginx-1.16.1-1.el7.ngx.x86_64.rpm
[root@m01 ~]
相当于在远程机器上执行:yum install -y https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
[root@m01 ~]
2.yum_repository 模块(傻子才用)
[root@m01 ~]
EXAMPLES:
- name: Add repository
yum_repository:
name: epel
description: EPEL YUM repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
file: external_repos
enabled: no
state: absent
[root@m01 ~]
[root@web01 ~]
[nginx.repo]
baseurl = http://nginx.org/packages/centos/7/$basearch/
enabled = 1
gpgcheck = 1
name = nginx stable repo
name
description
baseurl
gpgcheck
enabled
file
1.file参数不修改,name参数也不修改的前提下,是修改yum源
2.file参数不修改,name参数修改的情况下,是添加yum源