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

相关推荐
知已难寻7 小时前
Docker 入门:容器技术与 Docker 基础
java·运维·服务器·docker·云原生·容器
星恒随风13 小时前
MySQL 从零入门(三):表的约束详解
linux·服务器·数据库·笔记·mysql
坤坤子吖18 小时前
Linux网络编程:自定义应用层协议与 JSON 序列化
linux·服务器·网络·c++·笔记·json
青瓦梦滋18 小时前
Redis主从复制
服务器·数据库·redis·缓存·bootstrap
沫璃染墨19 小时前
从零入门计算机网络系列(十八):TCP连接管理详解——从三次握手与四次挥手到TIME_WAIT机制
运维·服务器·网络·c++·网络协议·tcp/ip·tcp
Felven20 小时前
华为鲲鹏920s芯片serdestool工具使用说明
linux·运维·服务器·华为·鲲鹏920·serdestool
LabVIEW开发20 小时前
Omron PLC:接 LabVIEW 常踩的 5 个坑
服务器·网络·labview·labview知识·labview功能·labview程序
我是koten1 天前
【运维杂谈】K8s遇到Terminating的名称空间删除不了怎么办?(解决方案亲测有效)
linux·运维·服务器·云原生·kubernetes·k8s·名称空间
Csvn1 天前
安装、升级与目录结构
后端·nginx
爱吃奥利奥_wen2 天前
SQL Server 基础语法详解:从建库建表到约束与增删改查
服务器·数据库·oracle