怎樣在ansible-playbook中批量搭建LAMP?針對這個問題,今天小編總結了這篇文章,希望幫助更多想學習LAMP的同學找到更加簡單易行的辦法。
yum -y install httpd
yum -y install mariadb-server mysql
systemctl start mairadb
yum -y install php php-mysql
vim /var/www/html/index.php
<?php
phpinfo();
?>
systemctl restart httpd
mkdir -pv /etc/ansible/lamp/roles/{prepare,httpd,mysql,php}/{tasks,files,templates,vars,meta,default,handlers}
cd /etc/ansible/
cp /etc/httpd/conf/httpd.conf lamp/roles/httpd/files/
cp /etc/my.cnf lamp/roles/mysql/files/
vim lamp/roles/prepare/tasks/main.yml
- name: provide yumrepo file
shell: rm -rf /etc/yum.repos.d/*.repo #刪除原有yum配置文件
shell: wget - o /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-repo #下載新的yum配置文件
- name: clean the yum repo
shell: yum clean all
- name: clean the iptables
shell: systemctl stop firewalld #關閉防火墻
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 #安裝httpd服務
- name: provide test page
copy: src=index.php dest=/var/www/html #提供測試頁
notify: restart httpd #當前面的copy執行成功后,通過notify通知名字為restart httpd的handlers運行
- name: restart httpd
service: name=httpd enabled=yes state=restarted #重啟httpd服務
vim lamp/roles/mysql/tasks/main.yml
- name: install the mysql
yum: name=mariadb-server state=present #安裝mysql服務
- name: mkdir date directory
shell: mkdir -p /mydata/data #創建掛載點目錄
- name: provide configration file
copy: src=my.cnf dest=/etc/my.cnf #拷貝mysql的配置文件
- name: chage the owner
shell: chown -R mysql:mysql /mydata/* #更改屬主和屬主
- name: start mariadb
service: name=mariadb enabled=yes state=started #啟動mysql服務
vim lamp/roles/php/tasks/main.yml
- name: install php
yum: name=php state=present #安裝php
- name: install php-mysql
yum: name=php-mysql state=present #安裝php與mysql交互插件
vim lamp/roles/site.yml
- name: LAMP build
remote_user: root
hosts: all
roles:
- prepare
- mysql
- php
- httpd
ansible-playbook -i /etc/ansible/hosts ./site.yml
看完上訴內容,你們掌握在ansible-playbook中批量搭建LAMP的方法了嗎?如果想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。