一、创建剧本config_nginx.yml。完成以下功能:
????1、安装nginx
????2、提供默认主页
????3、启动并开机自启服务。
[root@servera ansible]# vim config_nginx.yml
[root@servera ansible]# cat config_nginx.yml
---
- hosts: dev
tasks:
- name: install nginx
yum:
name: nginx
- name: index.html
copy:
content: 'This is nginx test page'
dest: /usr/share/nginx/html/index.html
- name: fierwalld
firewalld:
service: http
permanent: yes
immediate: yes
state: enabled
- name: nginx start
service:
name: nginx
enabled: yes
state: started
测试
?
二、创建一个名为packages.yml的剧本
????1、在dev, prod 和 test 主机组中安装 php 和 mariadb 软件包
????2、在dev 主机组中安装 Development Tools 包组
????3、升级dev主机组中主机的所有软件包
[root@servera ansible]# vim packages.yml
[root@servera ansible]# cat packages.yml
---
- name: play 1
hosts: dev,prod,test
tasks:
- name: yum php mariadb
yum:
name:
- php
- mariadb
- name: play 2
hosts: dev
tasks:
- name: install Development Tools
yum:
name: "@Development Tools"
- name: play 3
hosts: dev
tasks:
-name: update all page
yum:
name: "*"
state: latest
|