실습 Ansible Playbook 실습 - 시스템 및 서버 관리 - 서버 프로비저닝 자동화 VM - 구현 1
페이지 정보
작성자 꿈꾸는여행자 작성일 25-02-11 11:14 조회 2,802 댓글 0본문
안녕하세요.
꿈꾸는여행자입니다.
Ansible을 통한 Infra의 다양한 자동화 측면이 있습니다.
여러 가지 항목들을 기준으로 설계 및 구현 해보는 과정을 진행하고자 합니다.
이번 항목에서는 다음 내용을 기준으로
구현해 보겠습니다.
1. 시스템 및 서버 관리
1.1. 서버 프로비저닝 자동화 (Bare Metal, Cloud, VM)
- Host의 KVM 상태 확인
감사합니다.
> 아래
### **Ansible AWX 환경 테스트 - KVM 설치 및 상태 확인**
#### **1. 준비 작업**
- **프로젝트**: `lds-project`
- **인벤토리**: `lds-inventory`
- **호스트**: `kvm_host`
- `ansible_host`: `192.168.10.10`
---
#### **2. Playbook 작성**
- **경로**: `/var/lib/rancher/k3s/storage/pvc-f183a2c8-0714-45ed-8055-fd63ac526572_awx_awx-demo-projects-claim/lds-project`
- **파일명**: `check-kvm-installation-and-status.yaml`
- **내용**:
```yaml
---
- name: Check KVM Installation and Status
hosts: kvm_host
become: true
gather_facts: true
tasks:
- name: Check if KVM is supported on this system
ansible.builtin.command: egrep -c '(vmx|svm)' /proc/cpuinfo
register: kvm_support
changed_when: false
- name: Print KVM support information
ansible.builtin.debug:
msg: "KVM Support: {{ 'Yes' if kvm_support.stdout | int > 0 else 'No' }}"
- name: Check installed KVM-related packages
ansible.builtin.command: rpm -q qemu-kvm libvirt virt-install virt-manager bridge-utils
register: kvm_packages
changed_when: false
ignore_errors: true
- name: Print installed KVM packages
ansible.builtin.debug:
msg: "{{ kvm_packages.stdout_lines }}"
- name: Check libvirt service status
ansible.builtin.systemd:
name: libvirtd
register: libvirtd_status
changed_when: false
- name: Print libvirt service status
ansible.builtin.debug:
msg: "Libvirt Service: {{ 'Running' if libvirtd_status.status.ActiveState == 'active' else 'Stopped' }}"
- name: List running virtual machines
ansible.builtin.command: virsh list --all
register: virsh_list
changed_when: false
ignore_errors: true
- name: Print running virtual machines
ansible.builtin.debug:
msg: "{{ virsh_list.stdout_lines }}"
- name: Check available libvirt networks
ansible.builtin.command: virsh net-list --all
register: virsh_net_list
changed_when: false
ignore_errors: true
- name: Print libvirt network status
ansible.builtin.debug:
msg: "{{ virsh_net_list.stdout_lines }}"
- name: Check available libvirt storage pools
ansible.builtin.command: virsh pool-list --all
register: virsh_pool_list
changed_when: false
ignore_errors: true
- name: Print libvirt storage pools
ansible.builtin.debug:
msg: "{{ virsh_pool_list.stdout_lines }}"
```
---
#### **3. 템플릿 생성**
- **템플릿 이름**: `lds-template-check-kvm-installation-and-status`
- **설명**: `Check KVM Installation and Status`
- **작업 유형**: `run`
- **조직**: `linuxdatasystem`
- **인벤토리**: `lds-inventory`
- **프로젝트**: `lds-project`
- **실행 환경**: `AWX EE (latest)`
- **Playbook**: `check-kvm-installation-and-status.yaml`
---
#### **4. 템플릿 실행 결과**
##### ** Libvirt 네트워크 상태**
```
ok: [kvm_host] => {
"msg": [
" Name State Autostart Persistent",
"-----------------------------------------------------",
" ansible-network active yes yes",
" br0-net active yes yes",
" default active yes yes",
" internal-network active yes yes",
" shkwon-org-net active yes yes"
]
}
```
##### ** Libvirt 스토리지 풀 상태**
```
TASK [Check available libvirt storage pools] ***********************************
ok: [kvm_host]
TASK [Print libvirt storage pools] *********************************************
ok: [kvm_host] => {
"msg": [
" Name State Autostart",
"------------------------------------",
" default active yes",
" ISO active yes",
" ISO-data active yes",
" pool active yes",
" pool-data active yes",
" pool-leapp inactive yes"
]
}
```
##### ** 실행 요약**
```
PLAY RECAP *********************************************************************
kvm_host : ok=13 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
```
---
### ** 요약**
- **Ansible AWX를 활용하여 KVM 설치 및 상태를 점검하는 자동화 작업을 수행**하였습니다.
- `lds-project` 내에서 **Playbook을 작성**하고, **lds-inventory에 포함된 kvm_host(192.168.10.10)에서 실행**되었습니다.
- 실행 결과, **네트워크 및 스토리지 상태를 포함한 KVM 환경이 정상적으로 동작하고 있음**을 확인하였습니다.
- **추가적인 자동화**(예: KVM 미설치 시 자동 설치, 서비스 비활성화 시 재시작 등)가 필요하면 개선 가능.
---
- 이전글 Ansible Playbook 실습 - 시스템 및 서버 관리 - 서버 프로비저닝 자동화 VM - 구현 2
- 다음글 Ansible Playbook 실습 - 시스템 및 서버 관리 - 서버 프로비저닝 자동화 VM - 설계 1
댓글목록 0
등록된 댓글이 없습니다.
