ansible简单playbook剧本例子3-安装nginx

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

相关推荐
2601_9657984730 分钟前
How to Build a Custom Artisan Store on WordPress: Crafti Theme Review
linux·服务器·数据库
luyun0202021 小时前
论坛里的小工具,吾爱出品
运维·服务器·windows
江湖有缘1 小时前
Docker实战 | 使用Docker部署EasyNode服务器面板工具
服务器·docker·容器
你怎么知道我是队长1 小时前
计算机虚拟存储管理与页面置换算法详解
服务器·网络·算法
tjjingpan3 小时前
HCIP-Datacom Core Technology V1.0_20 IPv6概述
linux·服务器·网络
七七powerful3 小时前
为离线的bcliunx euler&龙晰 配置 yum源 nginx代理
nginx·yum·bclinux
数聚天成DeepSData4 小时前
外贸海关进出口数据去哪免费下载?从统计到明细的查找指南
linux·服务器·开发语言·前端·网络·人工智能·自然语言处理
Huangjin007_4 小时前
【Linux 系统篇(十)】基础开发工具(五) —— 第一个系统程序 - 进度条
linux·运维·服务器
路由侠内网穿透.4 小时前
本地部署开源日志收集系统 Log Bull 并实现外部访问
运维·服务器·网络·数据库·开源
AlbertS5 小时前
Let‘s Encrypt 证书自动续期并自动应用到Nginx
运维·nginx·ssl·cerbot·renew·续期