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

相关推荐
Java.熵减码农4 小时前
解决Linux修改环境变量后导致登录循环进不去系统的问题
linux·运维·服务器
明天好,会的4 小时前
分形生成实验(五):人机协同破局--30万token揭示Actix-web状态管理的微妙边界
运维·服务器·前端
C_心欲无痕5 小时前
nginx - alias 和 root 的区别详解
运维·前端·nginx
徐同保5 小时前
nginx转发,指向一个可以正常访问的网站
linux·服务器·nginx
我是苏苏7 小时前
Web开发:C#通过ProcessStartInfo动态调用执行Python脚本
java·服务器·前端
相偎8 小时前
Ubuntu搭建svn服务器
服务器·ubuntu·svn
咕噜企业分发小米9 小时前
有哪些开源的直播云服务器安全防护方案?
运维·服务器·云计算
C_心欲无痕10 小时前
nginx - 开启 gzip 压缩
运维·前端·nginx
开开心心_Every10 小时前
安卓后台录像APP:息屏录存片段,行车用
java·服务器·前端·学习·eclipse·edge·powerpoint
qq_3168377510 小时前
IP网段冲突 配置指定ip使用指定的网络接口发送,而不经过默认网关
服务器·网络·tcp/ip