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

相关推荐
jackzhuoa41 分钟前
Rust 异步核心机制剖析:从 Poll 到状态机的底层演化
服务器·前端·算法
艾莉丝努力练剑1 小时前
【Linux基础开发工具 (一)】详解Linux软件生态与包管理器:从yum / apt原理到镜像源实战
linux·运维·服务器·ubuntu·centos·1024程序员节
月巴月巴白勺合鸟月半1 小时前
生成私钥公钥
运维·服务器
七七七七071 小时前
【计算机网络】深入理解网络层:IP地址划分、CIDR与路由机制详解
linux·服务器·计算机网络·智能路由器
快乐的钢镚子1 小时前
思腾合力云服务器远程连接
运维·服务器·python
王道长服务器 | 亚马逊云1 小时前
AWS + SEO:让网站从服务器层面赢在搜索引擎起跑线
服务器·搜索引擎·aws
敲上瘾1 小时前
Linux系统C++开发工具(四)—— jsoncpp 使用指南
linux·服务器·网络·c++·json
小虚竹1 小时前
使用仓颉语言实现 nanoid:一个安全的唯一 ID 生成器
运维·服务器·安全·鸿蒙
chalmers_154 小时前
服务器启动的时候就一个对外的端口,如何同时连接多个客户端?
运维·服务器·网络
@木辛梓4 小时前
linux 信号
linux·运维·服务器