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

相关推荐
鱼跃鹰飞1 天前
Leetcode:97.交错字符串
linux·服务器·leetcode
XRJ040618xrj1 天前
Nginx下构建PC站点
服务器·前端·nginx
m0_737302581 天前
云服务器深度解析:技术内核、应用场景与上云避坑指南
服务器
前端玖耀里1 天前
详细介绍Linux命令dig和nslookup
linux·运维·服务器
星期五不见面1 天前
jetson naon super使用 sudo /opt/nvidia/jetson-io/jetson-io.py 界面闪退
linux·运维·服务器
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.1 天前
Nginx 平滑升级与回滚超详细指南
运维·nginx
坐怀不乱杯魂1 天前
Linux网络 - HTTPS
服务器·网络·网络协议·http·https
B2_Proxy1 天前
亚马逊采集的正确打开方式:从合规边界到反爬博弈,再到数据价值落地
服务器·网络·网络协议·tcp/ip·chatgpt
网硕互联的小客服1 天前
linux服务器忘记远程端口怎么办?如何找回?
linux·运维·服务器
历程里程碑1 天前
Linux 16 环境变量
linux·运维·服务器·开发语言·数据库·c++·笔记