ansible剧本练习
题目:
一、创建剧本config_nginx.yml。完成一下功能:
- 安装nginx
- 提供默认主页
- 启动并开机自启服务。
二、创建一个名为packages.yml的剧本
- 在dev、prod和test主机组中安装php和mariadb软件包
- 在dev主机组中安装Development Tools包组
- 升级dev主机组中主机的所有软件包
一、config_nginx.yml
[root@servera ansible]# vim config_nginx.yml
---
- name: nginx playbook
hosts: all
tasks:
- name: yum nginx
yum:
name:
- nginx
state: latest
- name: test page
copy:
content: 'This is nginx test page'
dest: /usr/share/nginx/html/index.html
- name: nginx enabled
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
- name: start
service:
name: nginx
enabled: yes
state: started
二、packages.yml
清单文件
[root@servera ansible]# vim packages.yml
``
-
name: install php, mariadb
hosts: dev,prod,test
tasks:- name: install php, mariadb
yum:
name:
- php
- mariadb
- name: install php, mariadb
-
name: install Development Tools
hosts: dev
tasks:- name: install Development Tools
yum:
name: “@Development Tools”
- name: install Development Tools
-
name: update all
hosts: dev
tasks:- name: update all
yum:
name: ‘*’
state: latest```
- name: update all