使用ansible远程部署最简易的LAMP

在ansible服务器上安装LAMP环境,然后,再将配置文件通过ansible拷贝到远程主机上,如果有配置文件不用在管理机安装LAMP

编写远程安装脚本

[root@node4 ~]# vim lamp-install.yaml

---

- name: yum install package

hosts: 192.168.0.52

remote_user: root

vars:

name1: epel-release

name2: httpd

name3: mariadb-server

name4: mariadb

name5: php

name6: php-mysql

tasks:

- name: install epel-release

shell: yum install -y {{ name1 }}

- name: install httpd

shell: yum install -y {{ name2 }}

- name: install mariadb-server

shell: yum install -y {{ name3 }}

- name: install mariadb

shell: yum install -y {{ name4 }}

- name: install php

shell: yum install -y {{ name5 }}

- name: install php-mysql

shell: yum install -y {{ name6 }}

- name: start httpd

shell: systemctl start {{ name2 }}

shell: systemctl enable {{ name2 }}

- name: start mariadb

shell: systemctl start {{ name4 }}

shell: systemctl enable {{ name4 }}

- name: restart mariadb

shell: systemctl restart {{ name4 }}

- name:

shell: echo -e "\" > /var/www/html/index.php

- name: restart httpd

shell: systemctl restart {{ name2 }}

语法检测

[root@node4 ~]# ansible-playbook --syntax-check lamp-install.yaml

使用ansible远程部署最简易的LAMP_第1张图片

远程安装LAMP

[root@node4 ~]# ansible-playbook lamp-install.yaml

使用ansible远程部署最简易的LAMP_第2张图片

Windows端访问测试

http://192.168.0.52/

使用ansible远程部署最简易的LAMP_第3张图片

你可能感兴趣的:(云计算,运维,经验分享,linux,服务器)