1.准备安装nginx剧本yml
vim install_nginx.yml
---
# 安装nginx 并启动
- hosts: web
remote_user: root
tasks:
- name: Add group nginx
group:
name: nginx
state: present
- name: Add user nginx
user:
name: nginx
state: present
group: nginx
- name: Install Nginx
yum:
name: nginx
state: present
- name: Copy the web page to the nginx directory
copy:
src: files/index.html
dest: /usr/share/nginx/html/index.html
- name: Start and enable Nginx service
service:
name: nginx
state: started
enabled: yes
- name: Stop the firewalld service
service:
name: firewalld
state: stopped
enabled: no
2.创建目录,准备一个简单首页
mkdir files && cd files
vim index.html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>这是根据剧本安装nginx 的简单例子</title>
</head>
<body>
<h1>这是根据剧本安装nginx 的简单例子</h1>
</body>
</html>
3.执行剧本
ansible-playbook install_nginx.yml
4.访问nginx
