실습 Ansible Playbook 실습 - Ansible AWX - Ansible AWX 설치 자동화 - 설계 2
페이지 정보
작성자 꿈꾸는여행자 작성일 25-02-21 18:33 조회 3,036 댓글 0본문
안녕하세요.
꿈꾸는여행자입니다.
Ansible을 통한 Playbook을 활용에 대해서 Ansible AWX 구성 자동화 방안을 생각해 보았습니다.
해당 항목들을 설계 및 구현 해보는 과정을 진행하고자 합니다.
이번 항목에서는 다음 내용을 기준으로
설계해 보겠습니다.
1. Ansible AWX Operator 설치를 위한 Ansible 기반 자동화
- Ansible AWX Container 항목 추가
감사합니다.
> 아래
### **X.2. AWX *
이 문서는 **Ansible**과 **AWX Operator**를 사용하여 **AWX**를 오프라인 환경에서 설치, 관리 및 제거하는 방법을 단계별로 설명합니다. 각 단계는 디렉토리 생성부터, 인벤토리 설정, 변수 파일 구성, 역할 정의, 그리고 Playbook 실행까지 포함합니다.
---
### **X.2.1. Ansible 프로젝트 디렉토리 자동 생성 (CLI)**
#### **1. 작업 디렉토리 생성**
- Ansible 프로젝트를 위한 기본 디렉토리를 생성합니다.
- **명령어 설명:**
```bash
mkdir awx # 'awx' 디렉토리 생성
cd awx # 'awx' 디렉토리로 이동
pwd # 현재 경로 확인
```
- **결과:** `/home/lds/Documents/with-ansible/awx`
---
#### **2. 기본 디렉토리 구조 생성**
- Ansible 프로젝트의 표준 디렉토리인 `group_vars`, `roles`, `files`를 생성합니다.
```bash
mkdir -p group_vars/ roles/ files/
```
---
#### **3. Ansible Galaxy로 roles 생성**
- Ansible Galaxy를 사용하여 각 역할(role) 디렉토리를 생성합니다.
- **역할 설명:**
- `prepare_awx_operator`: AWX Operator 설치를 위한 환경 설정
- `copy_offline_package`: 오프라인 패키지 준비
- `copy_awx_images`: 오프라인 이미지 복사
- `install_awx_operator`: AWX Operator 설치
- `clearup`: 설치된 자원의 정리
- **명령어 예시:**
```bash
ansible-galaxy init roles/prepare_awx_operator
```
---
### **X.2.2. Ansible 인벤토리 설정**
#### **1. inventory.ini 파일 작성**
- Ansible Playbook이 실행될 대상 노드를 정의합니다.
- **설정 파일 (`inventory.ini`):**
```ini
[all]
localhost ansible_connection=local ansible_user=lds ansible_become=true ansible_become_method=sudo
[k3s_nodes]
node1 ansible_host=192.168.50.22 ansible_user=lds ansible_become=true ansible_become_method=sudo ansible_ssh_common_args='-o StrictHostKeyChecking=no'
```
- **설명:**
- `localhost`: 제어 노드에서 로컬 연결
- `k3s_nodes`: AWX가 설치될 노드 정보
---
### **X.2.3. 변수 파일 (group_vars/all.yml)**
#### **1. 변수 파일 생성**
- 모든 Playbook에서 공통으로 사용할 변수를 한 곳에서 관리합니다.
- **예시 (`group_vars/all.yml`):**
```yaml
awx_namespace: "awx"
awx_admin_user: "admin"
awx_admin_password: "password"
awx_service_type: "NodePort"
awx_hostname: "awx.localdomain"
awx_operator_version: "2.19.1"
```
- **주요 변수:**
- `awx_namespace`: Kubernetes에서 AWX가 설치될 네임스페이스
- `awx_admin_user`/`password`: AWX UI 접근 계정 정보
- `awx_operator_version`: 설치할 AWX Operator 버전
---
### **X.2.4. Ansible `roles` 내용 작성 - AWX**
#### **1. prepare_awx_operator 역할 (제어 노드 환경 설정)**
- **설정 내용 (`roles/prepare_awx_operator/tasks/main.yml`):**
```yaml
- name: Install essential packages
dnf:
name:
- git
- python3-pip
- kubectl
- helm
state: present
- name: Clone awx-operator repository
git:
repo: "{{ awx_operator_repo_url }}"
dest: "{{ awx_operator_clone_path }}"
```
- **주요 작업:**
- 필수 패키지 설치
- AWX Operator 저장소 클론 및 버전 체크아웃
---
#### **2. copy_offline_package 역할 (오프라인 패키지 준비)**
- **설정 내용 (`roles/copy_offline_package/tasks/main.yml`):**
```yaml
- name: Export AWX Operator container images
shell: |
ctr -n k8s.io images pull {{ kube_rbac_proxy_image }}
ctr -n k8s.io images export {{ awx_operator_clone_path }}/{{ awx_images_archive }}
```
- **설명:**
- 필요한 모든 컨테이너 이미지를 다운로드하고, 오프라인 패키지로 압축하여 공유 디렉토리로 이동합니다.
---
#### **3. copy_awx_images 역할 (이미지 복사)**
- **설정 내용 (`roles/copy_awx_images/tasks/main.yml`):**
```yaml
- name: Load AWX images into K3s containerd
shell: |
ctr -n k8s.io images import {{ awx_operator_clone_path }}/{{ awx_images_archive }}
```
- **설명:**
- 오프라인 이미지 파일을 K3s 환경에 로드하여 설치 준비 완료
---
#### **4. install_awx_operator 역할 (설치)**
- **설정 내용 (`roles/install_awx_operator/tasks/main.yml`):**
```yaml
- name: Deploy AWX Operator using kustomize
shell: |
kustomize build . | kubectl apply -f -
- name: Apply AWX deployment manifest
copy:
dest: "{{ awx_operator_clone_path }}/awx-deployment.yaml"
content: |
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx
namespace: {{ awx_namespace }}
spec:
service_type: {{ awx_service_type }}
hostname: {{ awx_hostname }}
admin_user: {{ awx_admin_user }}
admin_password: {{ awx_admin_password }}
```
- **설명:**
- AWX Operator를 배포하고, AWX 인스턴스를 설치합니다.
---
#### **5. clearup 역할 (삭제 단계)**
- **설정 내용 (`roles/clearup/tasks/main.yml`):**
```yaml
- name: Remove Kubernetes AWX namespace
shell: |
kubectl delete namespace {{ awx_namespace }} || true
```
- **설명:**
- 모든 설치 파일과 Kubernetes 네임스페이스를 삭제하여 환경을 초기화합니다.
---
### **X.2.5. Ansible Playbook을 분리하여 실행**
#### **1. 준비 단계 (`prepare.yml`)**
```yaml
- name: Prepare environment for AWX Operator deployment
hosts: localhost
become: true
vars_files:
- group_vars/all.yml
roles:
- prepare_awx_operator
- copy_offline_package
```
- **실행 명령어:**
```bash
ansible-playbook -i inventory.ini prepare.yml --ask-pass --ask-become-pass
```
---
#### **2. 설치 단계 (`install-awx.yml`)**
```yaml
- name: Deploy AWX with Offline Installation
hosts: k3s_nodes
become: yes
vars_files:
- group_vars/all.yml
roles:
- copy_awx_images
- install_awx_operator
```
- **실행 명령어:**
```bash
ansible-playbook -i inventory.ini install-awx.yml --ask-pass --ask-become-pass
```
---
#### **3. 삭제 단계 (`clearup.yml`)**
```yaml
- name: Cleanup offline package from localhost
hosts: all
become: true
vars_files:
- group_vars/all.yml
roles:
- clearup
```
- **실행 명령어:**
```bash
ansible-playbook -i inventory.ini clearup.yml --ask-pass --ask-become-pass
```
---
### **요약**
- Ansible을 사용하여 **AWX Operator** 오프라인 설치 자동화
- **역할(Role)** 기반 구조로 유지보수 용이
- 오프라인 환경에서도 **K3s** 기반의 **AWX** 설치 가능
- 간단한 명령어로 설치 및 삭제 작업 수행
---
- 이전글 Ansible Playbook 실습 - Ansible AWX - Ansible AWX 설치 자동화 - 구현 1
- 다음글 Ansible Playbook 실습 - Ansible AWX - Ansible AWX 설치 자동화 - 설계 1
댓글목록 0
등록된 댓글이 없습니다.
