ansible简单playbook剧本例子3-安装nginx
1.准备安装nginx剧本yml
vim install_nginx.yml
---
# 安装nginx 并启动
- hosts: webremote_user: roottasks:- name: Add group nginxgroup:name: nginxstate: present- name: Add user nginxuser:name: nginxstate: presentgroup: nginx- name: Install Nginxyum:name: nginxstate: present- name: Copy the web page to the nginx directorycopy:src: files/index.htmldest: /usr/share/nginx/html/index.html- name: Start and enable Nginx serviceservice:name: nginxstate: startedenabled: yes- name: Stop the firewalld serviceservice:name: firewalldstate: stoppedenabled: 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