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

相关推荐
yuxb7314 分钟前
集群与负载均衡:HAProxy 与 Nginx 实践
运维·nginx·负载均衡
努力买辣条9 小时前
基于 Docker 的高可用 WordPress 集群部署:分布式 Nginx + Keepalived、MySQL 主从复制与 ProxySQL 读写分离
分布式·nginx·docker
IDIOT___IDIOT11 小时前
Linux mount 命令
linux·运维·服务器
暗流者12 小时前
AAA 服务器与 RADIUS 协议笔记
运维·服务器·笔记
青草地溪水旁14 小时前
服务发现实例和服务实例是不同的
服务器·服务发现·服务实例
于冬恋15 小时前
RabbitMQ高级
服务器·网络·rabbitmq
算力魔方AIPC16 小时前
如何用算力魔方4060安装PaddleOCR MCP 服务器
运维·服务器
tan77º17 小时前
【Linux网络编程】分布式Json-RPC框架 - 项目设计
linux·服务器·网络·分布式·网络协议·rpc·json
Ray Song17 小时前
【Linux】 wget、curl 用法区别
linux·运维·服务器·curl·wget
小妖66617 小时前
本地文件夹即时变身 Web 服务器(文件服务器)
运维·服务器