用ansible循环安装lamp

用ansible循环安装lamp

环境

主机名IP地址安装服务
control192.168.56.129ansible
server192.168.56.132apache

编写playbook

[root@control lamp]# cat LL.yml 
---
  - name: firewalld
    hosts: server3
    tasks:

      - name: stop firewalld
        service: 
          name: firewalld
          state: stopped
          enabled: no

      - name: stop selinux
        lineinfile:
          path: /etc/selinux/config
          regexp: "^SELINUX=enforcing"
          line: SELINUX=disabled
        
      - name: setenforce 0
        shell: "setenforce 0"
        failed_when: false
        
      - name: create users
        user: 
          name: "{{ item }}"
          system: yes
          state: present
        loop: 
           - name
           -  my
         
      - name: install  service
        yum: 
           name: " {{ item }}"
           state: present
        loop:
          - httpd
          - php
          - mariadb
          - mariadb-server
        
      - name: start service
        service:
          name: "{{ item }}"
          state: started
          enabled: yes
        loop: 
          - httpd
          - php-fpm
          - mariadb
  
      - name:  Create a file if it does not exist
        file: 
          path: /var/www/html/index.php
          state: touch
          mode: 0775
    
      - name:  ehco   index.php
        lineinfile:
          path: /var/www/html/index.php 
          line: |
            <?php
              phpinfo();
            ?>

运行

[root@control book]# ansible-playbook lamp/site.yaml 

PLAY [firewalld] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.56.132]

TASK [stop firewalld] **********************************************************
ok: [192.168.56.132]

TASK [stop selinux] ************************************************************
changed: [192.168.56.132]

TASK [setenforce 0] ************************************************************
changed: [192.168.56.132]

TASK [create users] ************************************************************
changed: [192.168.56.132] => (item=name)
changed: [192.168.56.132] => (item=my)

TASK [install  service] ********************************************************
changed: [192.168.56.132] => (item=httpd)
changed: [192.168.56.132] => (item=php)
changed: [192.168.56.132] => (item=mariadb)
changed: [192.168.56.132] => (item=mariadb-server)

TASK [start service] ***********************************************************
changed: [192.168.56.132] => (item=httpd)
changed: [192.168.56.132] => (item=php-fpm)
changed: [192.168.56.132] => (item=mariadb)

TASK [Create a file if it does not exist] **************************************
changed: [192.168.56.132]

TASK [ehco   index.php] ********************************************************
changed: [192.168.56.132]

PLAY RECAP *********************************************************************
192.168.56.132             : ok=9    changed=7    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   


查看端口

[root@server3 ~]# ss  -antl
State    Recv-Q   Send-Q       Local Address:Port                     Peer Address:Port                 
LISTEN   0        128                0.0.0.0:22                            0.0.0.0:*                    
LISTEN   0        80                       *:3306                                *:*                    
LISTEN   0        128                      *:80                                  *:*                    
LISTEN   0        128                   [::]:22                               [::]:*       

查看结果

[外链图片转存中…(img-cRV7lc4R-1627267591781)]在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值