ansible自动化部署web

红帽学习环境下的配置

ansible自动化部署web服务 项目(一) 任务一:安装httpd,firewalld软件包 任务二:创建网站资源文件 任务三:启动httpd,firewalld 任务四:添加防火墙规则 项目(二) uri测试 通过debug捕获打印测试结果

测试

首先,使用命令lab playbook-basic start 看节点服务能否正确开启

cd之后ll查看一下

编写配置文件

vim  inventory

把里面的serverc和serverd改成a和b

vim新文件 web.yml编写剧本

 

 方便复制,写在下面,但有的时候复制可能会出错,建议手打

---
- name: 服务配置
  hosts: web
  tasks:
    - name: install firewalld httpd
      yum:
        name:
         - firewalld
         - httpd
        state: latest
    - name: create index.html
      copy:
        content: "this is servera and serverb"
        dest: /var/www/html/index.html
    - name: start firewalld
      service:
        name: firewalld
        state: started
        enabled: true

    - name: firewalld-rule
      firewalld:
        port: 80/tcp
        permanent: true
        immediate: true
        state: enabled


    - name: start httpd
      systemd:
        name: httpd
        state: started
        enabled: true
- name: web test
  hosts: web
  tasks:
    - name: test
      uri:
        url: http://servera
        return_content: yes
        status_code: 200
      register: result
    - name: dayin
      debug:
        msg: "{{ result }}"
 

使用ansible-playbook    web.yml   -C测试

 没得问题,开始运行去掉-C

 

为能把结果全部显示,今天的截屏字有点小,见谅见谅!!! 

 做完咯

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值