Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to build LAMP in batch in ansible-playbook

Shulou Source: shulou.com Published: 2022-06-03 06:27:52 10月01日 Update

How to build LAMP in batch in ansible-playbook? To solve this problem, the editor summarized this article today, hoping to help more students who want to learn LAMP to find a more simple and easy way.

First install the LAMP environment on the ansible server, and then copy the configuration file to the remote host 1. 1 via ansible. Install httpd software yum-y install httpd2. Install mysqlyum-y install mariadb-server mysqlsystemctl start mairadb3. Install php and php-mysql module yum-y install php php-mysql4. Provide php test page vim / var/www/html/index.phpsystemctl restart httpd access ip:80 to see if the test page appears

Create the corresponding file mkdir-pv / etc/ansible/lamp/roles/ {prepare,httpd,mysql,php} / {tasks,files,templates,vars,meta,default Handlers} copy the configuration files of httpd and MySQL of the successfully built LAMP environment to the playbooks of the cd / etc/ansible/cp / etc/httpd/conf/httpd.conf lamp/roles/httpd/files/cp / etc/my.cnf lamp/roles/mysql/files/ write prepare role under the corresponding directory # pre-preparation vim lamp/roles/prepare/tasks/main.yml- name: provide yumrepo file shell: rm-rf / etc/yum.repos.d/*.repo # delete the original There is a yum configuration file shell: wget-o / etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-repo # download the new yum configuration file-name: clean the yum repo shell: yum clean all- name: clean the iptables shell: systemctl stop firewalld # turn off the firewall to build the httpd task cp / var/www/html/index.php lamp/roles/httpd/files/vim lamp/roles/httpd/tasks/main.yml- Name: web server install yum: name=httpd state=present # install the httpd service-name: provide test page copy: src=index.php dest=/var/www/html # provides a test page notify: restart httpd # when the previous copy is executed successfully Notify the handlers operation named restart httpd through notify-name: restart httpd service: name=httpd enabled=yes state=restarted # restart the httpd service deployment mariadb database to create the MySQL service task, you need to install the mysql service and change the attribute of the owner Start mysqlvim lamp/roles/mysql/tasks/main.yml- name: install the mysql yum: name=mariadb-server state=present # install mysql service-name: mkdir date directory shell: mkdir-p / mydata/data # create mount point directory-name: provide configration file copy: src=my.cnf dest=/etc/my.cnf # copy mysql configuration file-name: chage the owner shell: chown-R mysql:mysql / mydata/* # change owner and owner-name: start Mariadb service: name=mariadb enabled=yes state=started # start the mysql service build php task vim lamp/roles/php/tasks/main.yml- name: install php yum: name=php state=present # install php- name: install php-mysql yum: name=php-mysql state=present # install the php and mysql interaction plug-in define the entire task vim lamp/roles/site.yml- name: LAMP build remote_user: root hosts: all roles:-prepare-mysql-php- httpd execute playbookansible- Playbook-I / etc/ansible/hosts. / site.yml

Visit 192.168.1.129 to see if there is a test page

After reading the content of the appeal, have you mastered the method of building LAMP in batch in ansible-playbook? If you want to know more related content, welcome to follow the industry information channel, thank you for reading!

Tags: Service file configuration task test copy success content more environment directory easy easy host upfront method classmate name attribute plug-in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Docker Shulou Technology OPPO Reno