使用playbook简单循环部署lamp
主机 | |
---|
192.168.220.7 (ansible控制机) | CentOS8 | 192.168.220.8 (被控制机) | CentOS8 |
准备好本地配置文件
[root@localhost ansible]# ls # httpd.conf index.php www.conf
ansible.cfg group_vars host_vars httpd.conf index.php inventory loop roles vars www.conf
在loop目录下创建一个lamp.yml文件
[root@localhost ansible]# mkdir loop
[root@localhost loop]# cd loop/
[root@localhost loop]# vim lamp.yml
---
- name: Install lamp on one host
hosts: "*"
gather_facts: no
tasks:
- name: Use circular installation
yum:
name: "{{ item }}"
state: latest
loop:
- httpd
- mariadb
- mariadb-server
- php
- name: turn off firewall
service:
name: firewalld
state: stopped
- name: turn off selinux
lineinfile:
path: /etc/selinux/config
regexp: "^SELINUX="
line: "SELINUX=disabled"
- name: start mariadb
service:
name: mariadb
state: started
- name: Copy profile to /etc/httpd/conf/httpd.conf
copy:
src: /etc/ansible/httpd.conf
dest: /etc/httpd/conf/httpd.conf
- name: cp profile to /etc/php-fpm.d/www.conf
copy:
src: /etc/ansible/www.conf
dest: /etc/php-fpm.d/www.conf
- name: Create directory /www/abc
file:
path: /www/abc
state: directory
- name: cp index.php to www abc
copy:
src: /etc/ansible/index.php
dest: /www/abc/
- name: restart service
service:
name: "{{ item }}"
state: restarted
enabled: yes
loop:
- httpd
- php-fpm
使用浏览器访问
|