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

相关推荐
conkl7 分钟前
嵌入式 Linux 深度解析:架构、原理与工程实践(增强版)
linux·运维·服务器·架构·php·底层·堆栈
AI视觉网奇2 小时前
whisper tokenizer
linux·运维·服务器
MX_93592 小时前
使用Nginx部署前端项目
运维·前端·nginx
srrsheng3 小时前
电商前端Nginx访问日志收集分析实战
运维·前端·nginx
m0_738120723 小时前
Solar月赛(应急响应)——攻击者使用什么漏洞获取了服务器的配置文件?
运维·服务器·安全·web安全·网络安全
咕噜签名分发冰淇淋3 小时前
应用app的服务器如何增加高并发
运维·服务器
闻道且行之3 小时前
TTS语音合成|GPT-SoVITS语音合成服务器部署,实现http访问
服务器·gpt·http
胡西风_foxww4 小时前
Vue2 项目实现 Gzip 压缩全攻略:从配置到部署避坑指南
nginx·部署·vue2·配置·gzip·压缩·攻略
forestqq4 小时前
zabbix平台无法删除已停用主机的处理案例
运维·服务器·zabbix
大锦终5 小时前
【Linux】环境变量
linux·运维·服务器