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

相关推荐
薰衣草233313 分钟前
linux练习-2
linux·运维·服务器
驰羽43 分钟前
C++网络编程(三)TCP通信流程
服务器·网络·tcp/ip
夏日漱石_1 小时前
tcp 服务器的设计思路
服务器·网络·tcp/ip
洋葱圈儿6662 小时前
第八个实验——浮动路由
运维·服务器·网络
zym大哥大3 小时前
高并发内存池
服务器·数据库·windows
报错小能手4 小时前
linux学习笔记(18)进程间通讯——共享内存
linux·服务器·前端
de之梦-御风4 小时前
【Linux】 开启关闭MediaMTX服务
linux·运维·服务器
Morphlng5 小时前
wstunnel 实现ssh跳板连接
linux·服务器·网络·ssh
IT 小阿姨(数据库)5 小时前
PostgreSQL通过pg_basebackup物理备份搭建流复制备库(Streaming Replication Standby)
运维·服务器·数据库·sql·postgresql·centos
夜月yeyue6 小时前
ART 加速器、流水线与指令预测的关系详解
linux·服务器·c语言·单片机·嵌入式硬件·性能优化·嵌入式高阶技巧