vi installMySQL.yaml
- hosts: web
tasks:
- name: install MySQL
yum:
name:mariadb-server
- name: push my.cnf
copy:
src: /work/my.cnf
dest: /etc/my.cnf
- name: start MySQL daemon
service:
name: started
enabled: yes
:wq
# ansible-playbook installMySQL.yaml
#template组件调用模板
# vi my.cnf
server_id={{ db_id }}
bind-address={{ ansible_all_ipv4_addresses[0] }}
:wq
# mv my.cnf my.cnf.j2
vi installMySQL2.yaml
- hosts: web
tasks:
- name: install MySQL
yum:
name:mariadb-server
- name: push my.cnf
template:
src: /work/my.cnf.j2
dest: /etc/my.cnf
- name: start MySQL daemon
service:
name: started
enabled: yes
:wq
# ansible-playbook installMySQL2.yaml
#handlers组件重启服务
vi installMySQL3.yaml
- hosts: web
tasks:
- name: install MySQL
yum:
name:mariadb-server
- name: push my.cnf
template:
src: /work/my.cnf.j2
dest: /etc/my.cnf
notify: restart MySQL
- name: start MySQL daemon
service:
name: started
enabled: yes
handlers:
- name: restart MySQL
service:
name: mariadb
state: restarted
:wq
# ansible-playbook installMySQL3.yaml