Ansible---第二天

开始练习之前:开启环境

1、设置课程
清除课程:[kiosk@foundation0 ~]$ rht-clearcourse 0
设置课程:[kiosk@foundation0 ~]$ rht-setcourse rh294
2.启用环境
启用classroom(仅一次):[kiosk@foundation0 ~]$ rht-vmctl start classroom
启用其他服务器:[kiosk@foundation0 ~]$ rht-vmctl start all
查看状态:[kiosk@foundation0 ~]$ rht-vmctl status all
bastion RUNNING
workstation RUNNING
servera RUNNING
serverb RUNNING
serverc RUNNING
serverd RUNNING
重置环境:[kiosk@foundation0 ~]$ rht-vmctl reset servera
[kiosk@foundation0 ~]$ rht-vmctl fullreset servera

一、创建剧本config_nginx.yml。完成以下功能:

1、安装nginx
2、提供默认主页
3、启动并开机自启服务。

1.创建剧本

[student@workstation ansible]$ cat config_nginx.yml 
---
- hosts: dev
  tasks:
    - name: install nginx
      yum:
        name: nginx

    - name: index.html
      copy:
        content: 'This is test page.'
        dest: /usr/share/nginx/html/index.html

    - name: config service
      service:
        name: nginx
        state: started
        enabled: yes

    - name: firewalld
      firewalld:
        service: http
        permanent: yes
        immediate: yes
        state: enabled

2.运行剧本
Ansible---第二天_第1张图片

二、创建一个名为packages.yml的剧本

1、在dev, prod 和 test 主机组中安装 php 和 mariadb 软件包
2、在dev 主机组中安装 Development Tools 包组
3、升级dev主机组中主机的所有软件包

1.创建剧本

[student@workstation ansible]$ cat packages.yml 
---
- name: play 1
  hosts: dev,prod,test
  tasks:
    - name: install php and 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
      yum:
        name: '*'
        state: latest

2.运行剧本
Ansible---第二天_第2张图片

你可能感兴趣的:(linux,运维,ansible)