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

相关推荐
christine-rr19 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
東雪蓮☆19 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
乌萨奇也要立志学C++20 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy20 小时前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Yyyy48220 小时前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡
绿箭柠檬茶21 小时前
Ubuntu 服务器配置转发网络访问
服务器·网络·ubuntu
獭.獭.1 天前
Linux -- 信号【上】
linux·运维·服务器
路由侠内网穿透1 天前
本地部署 GPS 跟踪系统 Traccar 并实现外部访问
运维·服务器·网络·windows·tcp/ip
ZERO_pan1 天前
服务器装机遇到的问题
运维·服务器
l1t1 天前
利用DeepSeek实现服务器客户端模式的DuckDB原型
服务器·c语言·数据库·人工智能·postgresql·协议·duckdb