安装搭建LAMP架构

安装搭建LAMP架构

  • 安装搭建LAMP架构
    • 创建基本文件
    • 编写httpd模块
    • 编写mysql模块
    • 编写php模块
    • 编写roles示例

安装搭建LAMP架构

创建基本文件

mkdir /etc/ansible/roles/httpd/{files,templates,tasks,handlers,vars,defaults,meta} -p
mkdir /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,defaults,meta} -p
mkdir /etc/ansible/roles/php/{files,templates,tasks,handlers,vars,defaults,meta} -p

touch /etc/ansible/roles/httpd/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/mysql/{defaults,vars,tasks,meta,handlers}/main.yml
touch /etc/ansible/roles/php/{defaults,vars,tasks,meta,handlers}/main.yml

编写httpd模块

写一个简单的tasks/main.yml

vim /etc/ansible/roles/httpd/tasks/main.yml
- name: install apache
  yum: pkg={
     {
      servername }} state=latest

定义变量:可以定义在全局变量中,也可以定义在roles角色变量中.

vim /etc/ansible/roles/httpd/vars/main.yml 
servername: httpd

编写mysql模块

vim /etc/ansible/roles/mysql/tasks/main.yml 
- name: install mysql
  yum: pkg={
     {
      mysqlname }} state=latest
  
vim /etc/ansible/roles/mysql/vars/main.yml 
mysqlname: mariadb*

编写php模块

vim /etc/ansible/roles/php/tasks/main.yml 
- name: install php
  yum: pkg={
     {
      phpname }} state=latest
  
vim /etc/ansible/roles/php/vars/main.yml 
phpname: php

编写roles示例

vim /etc/ansible/site.yml
- hosts: webserver
  remote_user: root
  roles:
   - httpd
   - mysql
   - php

你可能感兴趣的:(ansible,php,apache)