ansible自动部署lamp平台

1、开始部署lamp角色

ansible自动部署lamp平台_第1张图片

2、准备lamp配置模板

注意:安装好Apache后会生成一个默认的欢迎界面,要先删除执行界面,在访问时添加两个测试界面,在进行访问。

[root@localhost roles]# cp /etc/httpd/conf/httpd.conf  /etc/ansible/roles/lamp/files/
[root@localhost roles]# ls lamp/files/
httpd.conf
[root@localhost roles]# 

并添加两个事先写好的测试页面

[root@localhost roles]# ls /var/www/html/
test1.php  test2.php
[root@localhost roles]# cp /var/www/html/* /etc/ansible/roles/lamp/files/
[root@localhost roles]# ls lamp/files/
httpd.conf  test1.php  test2.php
[root@localhost roles]# 

3、开始编写剧本

 

[root@localhost roles]# cat /etc/ansible/roles/lamp/tasks/main.yml 
---
# tasks file for lamp

- name: yum install
  yum:
     name={{ item }}
     state=present
  loop:
    - httpd 
    - php 
    - mariadb-server 
    - php-mysql 
    - gd 
    - php-gd 
    - php-devel
- name: rm welcome
  shell: rm -rf /etc/httpd/conf.d/welcome.conf
- name: copy1
  copy:
      src: httpd.conf
      dest: /etc/httpd/conf/httpd.conf
- name: copy2
  copy:
      src: test1.php
      dest: /var/www/html/test1.php
- name: copy3
  copy:
      src: test2.php
      dest: /var/www/html/test2.php
- name: start httpd
  service:
      name: httpd
      state: started
      enabled: yes
- name: start mariadb
  service:
      name: mariadb
      state: started
      enabled: yes
[root@localhost roles]# cat /opt/11/lamp.yaml 
- hosts: sqlserver
  user: root
  roles:
      - lamp

4、剧本完成,执行剧本

ansible自动部署lamp平台_第2张图片

 ansible自动部署lamp平台_第3张图片

 5、验证测试(用被管理机访问)

ansible自动部署lamp平台_第4张图片

 

你可能感兴趣的:(linux,自动化,运维,apache)