当前位置: 首页 > news >正文

使用Ansible的playbook安装HTTP

实验环境

安装好ansible

一、准备测试服务(192.168.10.41)

1、安装HTTP服务

dnf -y install httpd

2、启动HTTP服务

systemctl start httpd

3、使用浏览器访问

192.168.10.41

因为开启了防火墙,所有无法访问

4、开放防火墙的80端口

firewall-cmd --add-port=80/tcp --permanent

firewall-cmd --reload

firewall-cmd --list-all

5、再次使用浏览器访问

192.168.10.41

6、编写网页

cd /var/www/html/

vim index.html

添加:

<html>

        <head>

                <title>hello world</title>

        </head>

        <body>

                <h1>hello abc</h1>

                <p>This page is used to test the proper operation of an HTTP server after it has been installed on a Rocky Linux system. If you can read this page, it means that the software is working correctly.</p>

                <img src="1.jpg">

        </body>

</html>

上传一张图片到/var/www/html目录并改名为1.jpg

7、使用浏览器访问

192.168.10.41

8、修改HTTP服务的默认网页路径

mkdir /mysite

cp /var/www/html/* /mysite/

vim /etc/httpd/conf/httpd.conf

修改:

10、重启HTTP访问并访问

systemctl restart httpd

二、编写安装HTTP服务的playbook(192.168.10.40)

1、创建目录

mkdir /myplaybook

cd /myplaybook/

2、从192.168.10.41上拉取配置文件

ansible -m fetch -a 'src=/etc/httpd/conf/httpd.conf dest=./' 192.168.10.41

mv 192.168.10.41/etc/httpd/conf/httpd.conf ./

3、压缩192.168.10.41的网页文件并拉取到ansible

ansible -m archive -a 'path=/mysite dest=/root/mysite.tar.gz' 192.168.10.41

ansible -m fetch -a 'src=/root/mysite.tar.gz dest=./' 192.168.10.41

mv 192.168.10.41/root/mysite.tar.gz ./

4、编写playbook

vim install-httpd.yml

添加:

- hosts: 192.168.10.42

  tasks:

    - name: install package

      dnf: name=httpd state=installed

    - name: modify configfile

      copy: src=httpd.conf dest=/etc/httpd/conf/httpd.conf backup=yes

    - name: create web directory

      file: path=/mysite state=directory

    - name: copy web site

      copy: src=mysite.tar.gz dest=/mysite

    - name: uncompress web package

      unarchive: src=/mysite/mysite.tar.gz dest=/ remote_src=yes

    - name: set firewalld

      firewalld: port=80/tcp state=enabled permanent=yes immediate=yes

    - name: start http service

      systemd: name=httpd state=started enabled=yes

5、测试运行playbook

ansible-playbook -C install-httpd.yml

因为测试不会创建目录,所以才会报错

列出 Ansible 剧本(playbook)install-httpd.yml 中将会影响的主机(hosts)清单

ansible-playbook --list-hosts install-httpd.yml

列出 Ansible playbook(install-httpd.yml)中定义的所有任务(tasks)

ansible-playbook --list-tasks install-httpd.yml

运行playbook

ansible-playbook install-httpd.yml

6、使用浏览器访问验证

192.168.10.42

http://www.dtcms.com/a/264170.html

相关文章:

  • 8.4 Jmter实践不同线程组之间的全局变量的传递和使用
  • 使用 StatsD 向 TDengine 写入
  • 鸿蒙系统(HarmonyOS)应用开发之实现电子签名效果
  • jQuery EasyUI 安装使用教程
  • 苹果AR/VR头显路线图曝光,微美全息推进AI/AR智能眼镜新品开启视觉体验篇章
  • 视频断点续播全栈实现:基于HTML5前端与Spring Boot后端
  • C++编程语言:标准库:STL算法(Bjarne Stroustrup)
  • Python学习Day48
  • 3.1.1.9 安全基线检查项目九:检查是否设置限制su命令用户组
  • 微软服务器安全问题
  • 代码随想录day21二叉树8
  • 可信数据空间:概念、架构与应用实践
  • kafka自定义分区器
  • Webpack的插件机制Tapable
  • 华为认证二选一:物联网 VS 人工智能,你的赛道在哪里?
  • 打造 AI 产品的前端架构:响应式、流式、智能交互三合一
  • uv介绍以及与anaconda/venv的区别
  • C#系统学习第七章——数组
  • python 继承
  • 《UE5_C++多人TPS完整教程》学习笔记39 ——《P40 远程过程调用(Remote Procedure Calls)》
  • 增材制造研究领域:3D 打印设计国际会议
  • 责任链模式 Go 语言实战
  • 电脑系统重装有什么用?
  • 动手实践:如何提取Python代码中的字符串变量的值
  • AI问答-vue3:如何选择使用reactive或ref
  • 【HarmonyOS】鸿蒙使用仓颉编程入门
  • 基于Halcon平台的常规OCR与深度OCR性能对比分析
  • 设计模式(行为型)-访问者模式
  • python训练day46 通道注意力
  • 【kernel8】spi协议,验证,模型,设备树处理,spidev,衍生协议