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

相关推荐
小则又沐风a1 分钟前
深入理解文件系统(二)
java·服务器·前端
weixin_5450193225 分钟前
Nginx 配置SSL实现HTTPS访问
nginx·https·ssl
天蓝的想29 分钟前
Kueue 如何管理 DRA 模式下的 GPU 配额
运维·服务器
恒5399 小时前
Linux文件系统I
linux·运维·服务器
阿成学长_Cain9 小时前
Linux ipcs 命令超全详解:查看共享内存 / 消息队列 / 信号量,IPC 运维必备
linux·运维·服务器·网络·数据库
青瓦梦滋10 小时前
协议定制/序列化-反序列化(Linux视角)
linux·服务器·网络·c++
MDM.Plus16 小时前
苹果MDM技术演进:从远程控制到设备信任体系的构建
运维·服务器·安全·ios·mdm·手机店
写代码的学渣17 小时前
Linux systemd 开机启动日志逐行详细解析报告
linux·运维·服务器
skd899918 小时前
万能查任意网络设备IP工具
服务器·网络·tcp/ip