Ansible-Playbook部署lamp(循环)

Ansible-Playbook部署lamp(循环)

环境

主机ip
Ansible192.168.200.152
受管主机192.168.200.154
//首先这两台主机是能ping通的
[root@ansible playbook]# ansible 192.168.200.154 -m ping
192.168.200.154 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
//编写部署lamp的install.yml
[root@ansible playbook]# vim install.yml
---
- hosts: 192.168.200.154
  tasks: 
    - name: install service
      yum: 
        name: "{{ item }}"
        state: present
      loop: 
        - httpd
        - httpd-devel
        - mariadb
        - mariadb-server
        - mariadb-devel
        - php
        - php-mysql*
        - php-*

    - name: create user
      user: 
        name: "{{ item }}"
        system: yes
        shell: /sbin/nologin
      loop: 
        - httpd
        - mysql
        - www

    - name: start service
      service: 
        name: "{{ item }}"
        state: started
        enabled: yes
      loop: 
        - httpd
        - mariadb

    - name: create index.php
      shell: 'echo "<?php phpinfo(); ?>" > /var/www/html/index.php'

执行结果

[root@ansible ansible]# ansible-playbook /opt/playbook/install.yml 

PLAY [192.168.200.154] *********************************************************

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

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

TASK [create user] *************************************************************
changed: [192.168.200.154] => (item=httpd)
ok: [192.168.200.154] => (item=mysql)
changed: [192.168.200.154] => (item=www)

TASK [start service] ***********************************************************
changed: [192.168.200.154] => (item=httpd)
changed: [192.168.200.154] => (item=mariadb)

TASK [create index.php] ********************************************************
changed: [192.168.200.154]

PLAY RECAP *********************************************************************
192.168.200.154            : ok=2    changed=13    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

访问

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值