Ansible-playbook使用循环部署lamp
主机 | |
---|
192.168.240.30 (ansible控制机) | CentOS8 |
192.168.240.40 (被控制机) | CentOS8 |
配置文件
[root@localhost ansible]# ls #httpd.conf、 www.conf、 index.pxp
'\' 1 ansible.cfg cctv fhq.yml ggyy.yml group_vars hosts host_vars httpd.conf index.php install.yml lamp.yml llqq.yml playbook qd.yml roles shishi.yml www.conf
编写lamp.yml文件
---
- name: install lamp on one host
hosts: 192.168.240.40
tasks:
- name: http mysql php
yum:
name: "{{ item }}"
state: present
loop:
- httpd
- mariadb
- mariadb-server
- php
- name: firewall
service:
name: firewall
state: stopped
- name: copy httpd.conf
copy:
src: /etc/ansible/httpd.conf
dest: /etc/httpd/conf/httpd.conf
- name: copy www.conf
copy:
src: /etc/ansible/www.conf
dest: /etc/php-fpm.d/www.conf
- name: create /www/abc
file:
path: /www/abc
state: directory
- name: copy index.php
copy:
src: /etc/ansible/index.php
dest: /www/abc
- name: selinux
lineinfile:
path: /etc/selinux/config
regexp: "^SELINUX="
line: "SELINUX=disabled"
- name: state
service:
name: "{{ item }}"
state: started
enabled: yes
loop:
- httpd
- php-fpm
访问网站测试
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/035cedd92f12f43b9a061819109bbd3a.png#pic_center)