一、安装Nginx
#可通过ansible-doc yum 查看对应的帮助文档
[root@Ansible ~]# ansible test -m command -a "wget -O /etc/yum.repos.d/epel.repo" #下载epel源
[root@Ansible ~]# ansible test -m command -a "yum clean all" -u cedar -b
[root@Ansible ~]# ansible test -m command -a "yum makecache" -u cedar -b
[root@Ansible ~]# ansible test -m command -a "yum info nginx" -u cedar -b
[root@Ansible ~]# ansible test -m yum -a "name=nginx state=present" -u cedar -b
10.3.153.8 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"nginx"
]
},
[root@Ansible ~]# ansible test -m command -a "nginx -v" -u cedar -b #验证是否成功
10.3.153.8 | CHANGED | rc=0 >>
nginx version: nginx/1.16.1
二、启动nginx与开机启动
1、验证test服务器当前状态
[root@ansible-test ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@ansible-test ~]# systemctl | grep nginx
[root@ansible-test ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@ansible-test ~]# systemctl list-unit-files | grep nginx
nginx.service disabled
2、启动nginx并设置开机启动
[root@Ansible ~]# ansible test -m service -a "name=nginx state=started enabled=yes" -u cedar -b
10.3.153.8 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"enabled": true,
"name": "nginx",
"state": "started",
"status": {
3、验证结果
二、安装redis
1、检查yum源是否可安装redis
[root@Ansible ~]# ansible test -m command -a "yum info redis" -u cedar -b
2、安装
redis[root@Ansible ~]# ansible test -m yum -a "name=redis state=present" -u cedar -b
3、验证
[root@Ansible ~]# ansible test -m command -a "redis-cli --version" -u cedar -b
10.3.153.8 | CHANGED | rc=0 >>
redis-cli 3.2.12
三、安装MariaDB
[root@Ansible ~]# ansible test -m command -a "yum info mariadb" -u cedar -b
10.3.153.8 | CHANGED | rc=0 >>
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.ustc.edu.cn
Available Packages
Name : mariadb
Arch : x86_64
Epoch : 1
Version : 5.5.68
Release : 1.el7
Size : 8.8 M
Repo : base/7/x86_64
Summary : A community developed branch of MySQL
URL : http://mariadb.org
License : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a community developed branch of MySQL.
: MariaDB is a multi-user, multi-threaded SQL database server.
: It is a client/server implementation consisting of a server daemon
: (mysqld) and many different client programs and libraries. The
: base package contains the standard MariaDB/MySQL client programs
: and generic MySQL files.
[root@Ansible ~]# ansible test -m yum -a "name=mariadb state=present" -u cedar -b
10.3.153.8 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": true,
"changes": {
"installed": [
"mariadb"
]
},
"msg": "",
"rc": 0,
来源:oschina
链接:https://my.oschina.net/u/4291367/blog/4914906