yum 集中式安装lamp
---
- name: LAMP install
hosts: dbservers
tasks:
- name: disable firewalld
service:
name: firewalld
enabled: no
state: stopped
- name: disabled selinux
shell: "sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"
shell: "iptables -F"
- name: install httpd
yum:
name: httpd
state: present
- name: install mariadb
yum:
name: mariadb-server
state: present
- name: install php
yum:
name: php,php-mysql,php-gd
state: present
- name: start mariadb
service:
name: mariadb
enabled: yes
state: started
- name: new db passwd
shell: 'mysqladmin -u root password "123456"'
- name: start http
service:
name: httpd
enabled: yes
state: started
- name: copy index.php
copy: src=index.php dest=/var/www/html/index.php
- name: reboot
reboot:
reboot_timeout: 60
...
网页验证
分布式安装lamp
---
- name: this is deploy lamp service by yum install
remote_user: root
hosts: all
gather_facts: false
tasks:
- name: stop firewalld
service: name=firewalld state=stopped
- name: stop seliunx
command: '/usr/sbin/setenforce 0'
ignore_errors: true
- name: cope nginx.repo file
copy: src=/opt/nginx.repo dest=/etc/yum.repos.d
when: inventory_hostname == "192.168.50.25"
- name: yum install nginx service
yum: name=nginx state=latest
when: inventory_hostname == "192.168.50.25"
- name: start nginx service
service: name=nginx state=started enabled=yes
when: inventory_hostname == "192.168.50.25"
- name: yum install php service
yum: name=php state=latest
when: inventory_hostname == "192.168.50.26"
- name: copy test file
copy: src=/opt/index.php dest=/var/www/html
when: inventory_hostname == "192.168.50.26"
- name: yum install mariadb state=latest
yum: name=mariadb
when: inventory_hostname == "192.168.50.27"
- name: yum install mariadb-server
yum: name=mariadb-server state=latest
when: inventory_hostname == "192.168.50.27"
- name: start mariadb service
service: name=mariadb state=started enabled=yes
when: inventory_hostname == "192.168.50.27"
- name: modify nginx.conf to connect php with nginx
copy: src=/opt/default.conf dest=/etc/nginx/conf.d/default.conf
when: inventory_hostname == "192.168.50.25"
- name: restart nginx
service: name=nginx state=restarted
when: inventory_hostname == "192.168.50.25"
- name: new mariadb passwd
shell: 'mysqlaadim -u root password "abc123"'
when: inventory_hostname == "192.168.50.25"
远程挂载镜像
---
- name: this is test for mount
hosts: webservers
remote_user: root
tasks:
- name: mount test
mount:
src: /dev/sr0
path: /mnt
state: mounted
fstype: 'iso9660'
三:通过role分布式YUM安装lnmp
建立role的文件夹
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} -ptouch /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
安装nginx 服务
安装php服务
准备文件
安装mysql服务
vim site.yml
运行剧本
ansible-playbook site.yum