실습 Ansible Playbook 실습 - Ansible AWX - Ansible AWX 설치 자동화 - 구현 1
페이지 정보
작성자 꿈꾸는여행자 작성일 25-02-27 15:29 조회 3,086 댓글 0본문
안녕하세요.
꿈꾸는여행자입니다.
Ansible을 통한 Playbook을 활용에 대해서 Ansible AWX 구성 자동화 방안을 생각해 보았습니다.
해당 항목들을 설계 및 구현 해보는 과정을 진행하고자 합니다.
이번 항목에서는 다음 내용을 기준으로
구현해 보겠습니다.
1. Ansible AWX Operator 설치를 위한 Ansible 기반 자동화
- 제어 노드에서 환경을 준비하고, 필요한 패키지를 설치
- 오프라인 설치를 위해 컨테이너 이미지를 다운로드 및 저장
감사합니다.
> 아래
## **AWX 설치 준비 과정 설명 및 파일 내용 정리**
AWX 설치를 위한 Ansible 환경을 설정하는 과정입니다. **제어 노드에서 환경을 준비하고, 필요한 패키지를 설치하며, 오프라인 설치를 위해 컨테이너 이미지를 다운로드 및 저장하는 과정**이 포함됩니다.
---
## **1. 변수 파일 설정 (group_vars/all.yml)**
이 파일은 **AWX 및 AWX Operator를 설치할 때 필요한 모든 변수들을 한 곳에서 관리**합니다.
**주요 변수 내용**
- **AWX 네임스페이스 및 관리 정보**
- `awx_namespace`: 네임스페이스 지정 (`awx`)
- `awx_admin_user`, `awx_admin_password`: AWX 관리자 계정 정보
- `awx_service_type`: `NodePort` 방식으로 서비스 노출
- `awx_hostname`: `awx.localdomain`
- **AWX Operator 관련 정보**
- `awx_operator_version`: 설치할 AWX Operator 버전 (`2.19.1`)
- `awx_operator_repo_url`: AWX Operator GitHub 저장소
- `awx_operator_clone_path`: 클론할 경로 (`/opt/awx-operator`)
- **컨테이너 이미지 및 저장 경로**
- `k3s_image_path`: K3s 이미지 저장 경로 (`/var/lib/rancher/k3s/agent/images`)
- `awx_images_archive`: 오프라인 설치용 이미지 저장 파일 (`awx-images.tar`)
- `awx_files_target_path`: 최종적으로 파일을 이동할 위치 (`/var/www/html/awx-files`)
- **AWX 및 관련 컨테이너 이미지 정보**
- `kube_rbac_proxy_image`, `awx_operator_image`, `awx_ee_image`, `awx_main_image` 등
**파일 내용**
```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_operator_local_path: "files/awx-operator.tar.gz"
awx_operator_remote_path: "/opt/awx-operator.tar.gz"
awx_operator_extract_path: "/opt/awx-operator"
k3s_image_path: "/var/lib/rancher/k3s/agent/images"
awx_operator_repo_url: "https://github.com/ansible/awx-operator.git"
awx_operator_clone_path: "/opt/awx-operator"
awx_images_archive: "awx-images.tar"
awx_files_target_path: "/var/www/html/awx-files"
awx_version: "24.6.1"
kube_rbac_proxy_image: "gcr.io/kubebuilder/kube-rbac-proxy:v0.15.0"
awx_operator_image: "quay.io/ansible/awx-operator:2.19.1"
awx_ee_image: "quay.io/ansible/awx-ee:24.6.1"
awx_main_image: "quay.io/ansible/awx:24.6.1"
centos_stream_image: "quay.io/centos/centos:stream9"
postgresql_image: "quay.io/sclorg/postgresql-15-c9s:latest"
redis_image: "docker.io/library/redis:7"
```
---
## **2. 제어 노드 환경 설정 (roles/prepare_awx_operator/tasks/main.yml)**
이 단계에서는 **제어 노드에서 필요한 패키지를 설치하고, containerd를 설정하며, AWX Operator 저장소를 클론하는 작업**을 진행합니다.
**주요 작업**
- Podman 및 Runc 제거 (`dnf remove -y podman runc`)
- **필수 패키지 설치**
- Git, Python3-pip, DNF 플러그인 (`dnf-plugins-core`)
- DNF 캐시 초기화 및 메타데이터 새로고침
- **containerd.io 설정**
- Docker CE 저장소 추가 (`dnf config-manager --add-repo`)
- `containerd.io` 설치 및 기본 설정 파일 생성 (`containerd config default`)
- containerd 서비스 재시작 및 활성화
- **kustomize 설치**
- **AWX Operator 저장소 클론 및 특정 버전 체크아웃**
**파일 내용**
```yaml
---
- name: Remove conflicting packages before installation
shell: |
dnf remove -y podman runc
ignore_errors: true
- name: Install essential packages
dnf:
name:
- git
- python3-pip
- dnf-plugins-core
state: present
- name: Clear DNF cache and refresh metadata
shell: |
dnf clean all && dnf makecache
- name: Add Docker CE repository for containerd.io
command: dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
args:
creates: /etc/yum.repos.d/docker-ce.repo
- name: Install containerd.io from Docker repository
dnf:
name:
- containerd.io
state: present
- name: Generate default containerd configuration
shell: |
containerd config default | tee /etc/containerd/config.toml
args:
creates: /etc/containerd/config.toml
- name: Restart and enable containerd service
systemd:
name: containerd
state: restarted
enabled: yes
- name: Install kustomize
shell: |
curl -sLO "https://github.com/kubernetes-sigs/kustomize/releases/latest/download/kustomize_linux_amd64"
chmod +x kustomize_linux_amd64
mv kustomize_linux_amd64 /usr/local/bin/kustomize
args:
creates: /usr/local/bin/kustomize
- name: Clone awx-operator repository
git:
repo: "{{ awx_operator_repo_url }}"
dest: "{{ awx_operator_clone_path }}"
- name: Checkout specified awx-operator version
shell: |
git checkout tags/{{ awx_operator_version }}
args:
chdir: "{{ awx_operator_clone_path }}"
```
---
## **3. 오프라인 패키지 준비 (roles/copy_offline_package/tasks/main.yml)**
이 단계에서는 **K3s 컨테이너 이미지를 다운로드하고, 오프라인 설치를 위해 내보내는 과정**이 포함됩니다.
**주요 작업**
1. **필요한 컨테이너 이미지 다운로드**
- `ctr -n k8s.io images pull` 명령을 이용해 필요한 모든 이미지 다운로드
2. **이미지 존재 여부 확인**
- `ctr -n k8s.io images ls` 실행 후 결과 출력
3. **오프라인 설치용 tar 파일 생성**
- `ctr -n k8s.io images export`를 이용해 모든 이미지를 `awx-images.tar` 파일로 저장
4. **오프라인 패키지 이동**
- `/var/www/html/awx-files`로 파일 이동
**파일 내용**
```yaml
---
- name: Pull required AWX images
shell: |
ctr -n k8s.io images pull {{ kube_rbac_proxy_image }}
ctr -n k8s.io images pull {{ awx_operator_image }}
ctr -n k8s.io images pull {{ awx_ee_image }}
ctr -n k8s.io images pull {{ awx_main_image }}
ctr -n k8s.io images pull {{ centos_stream_image }}
ctr -n k8s.io images pull {{ postgresql_image }}
ctr -n k8s.io images pull {{ redis_image }}
register: image_pull_result
changed_when: "'unpacking' in image_pull_result.stdout"
- name: Verify images are available in containerd
shell: ctr -n k8s.io images ls
register: image_list_result
changed_when: false
- name: Debug image list
debug:
var: image_list_result.stdout_lines
- name: Export AWX images to a tar file
shell: |
ctr -n k8s.io images export {{ awx_operator_clone_path }}/{{ awx_images_archive }} \
{{ kube_rbac_proxy_image }} \
{{ awx_operator_image }} \
{{ awx_ee_image }} \
{{ awx_main_image }} \
{{ centos_stream_image }} \
{{ postgresql_image }} \
{{ redis_image }}
register: export_result
failed_when: "'error' in export_result.stderr or export_result.rc != 0"
changed_when: true
- name: Debug export result
debug:
var: export_result.stderr_lines
when: export_result.rc != 0
- name: Move prepared files to shared directory
shell: |
mkdir -p {{ awx_files_target_path }}
mv {{ awx_operator_clone_path }} {{ awx_files_target_path }}
```
---
댓글목록 0
등록된 댓글이 없습니다.
