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

相关推荐
数字新视界2 小时前
信创动环监控实现机房能耗可视化与用电异常预警
服务器·数据中心·机房·环境管理·环控系统
笔记本note2 小时前
Linux 文件系统与设备文件
linux·服务器·文件系统
无足鸟ICT3 小时前
【RHCA+】_proc_pid_cmdline
linux·运维·服务器
饿了吃洗衣凝珠4 小时前
shell循环
linux·运维·服务器
feasibility.6 小时前
电脑一天重启3次、WiFi还消失:蓝屏0x9F背后,是MT7921网卡撞上Windows电源管理
服务器·网络·windows·wifi·电脑·网卡·驱动
顧棟6 小时前
INFINI Gateway 启动过程分析
服务器·网络·gateway
xbzb8 小时前
服务器与网络:从一台裸机到能联网跑服务(5 篇)
服务器·网络·ip·raid·blog.csdn.net·article
Hhy_11079 小时前
【Linux 进击之路 · 01】起航篇:从认识操作系统到XShell 远程连接、多叉树目录体系到高频基础指令全解析
linux·服务器·后端·学习
Eyfcom9 小时前
〖物流自动化测试 03〗Chaos Mesh 在物流微服务中的故障注入:从 Pod 宕机到业务逻辑故障的工程实践
服务器·微服务·架构·快递系统·物流自动化测试
xurileidian9 小时前
第 21 篇 · 边玩边学Python · if elif else 与缩进归属
java·服务器·网络