1、ansible playbook脚本,安装LAMP套件,lamp.yml
:
---
- name: LAMP install
hosts: xuegod135.cn
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
- name: test web page
uri:
url: http://xuegod135
status_code: 200
...
2、校验语法是否正确:
ansible-playbook lamp.yml --syntax-check
运行截图:
3、执行脚本:
ansible-playbook lamp.yml
运行截图:
注意:如果第一次执行失败了,需要二次执行,记得修改new db passwd
的任务,加上旧密码和新密码:
- name: new db passwd
shell: 'mysqladmin -u root -p 123456 password "你的新密码"'