Skip to content

Commit 0d4e0a6

Browse files
authored
Add documentation for openinfra korea forum
Documented the Ansible module used for translating Zuul documentation, including requirements, playbook tasks, and module details.
1 parent fff66f1 commit 0d4e0a6

1 file changed

Lines changed: 167 additions & 0 deletions

File tree

week6/contribution_gyuhwan.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# Zuul 문서 번역을 위한 Ansible module
2+
3+
Ansible playbook을 통한 Zuul 문서 번역에 사용한 module 정리입니다.
4+
5+
---
6+
7+
## Requirements
8+
9+
1. Using **Shell script** to build HTML documentation
10+
11+
[build-translated-lang.sh](https://github.com/openstack-kr/zuul-study/blob/main/l10n-artifact/build-translated-lang.sh)
12+
13+
위 쉘 스크립트를 사용합니다. 수행하는 작업은 아래와 같습니다.
14+
15+
* A. virtual environment 생성
16+
* B. venv에 dependencies 설치
17+
* C. po 파일 컴파일을 통한 mo파일 생성
18+
* D. 번역된 HTML파일 빌드
19+
20+
2. Using Zuul with **Ansible playbook**
21+
22+
Zuul 환경에 Job을 추가해서 번역한 po파일을 커밋하면 번역된 HTML파일이 생성되도록 합니다.
23+
24+
---
25+
26+
## Ansible playbook
27+
번역을 위해 playbook에 포함할 작업은 다음과 같습니다.
28+
29+
* 파이썬 환경설정
30+
* Zuul repository 클론
31+
* 프로젝트의 번역된 po파일을 zuul/doc/source/locale로 복사
32+
* 번역 문서 빌드 스크립트 실행
33+
* 결과물(HTML) 가져오기
34+
35+
---
36+
37+
## Ansible module
38+
위 playbook 작성에 사용한 module들 입니다.
39+
40+
* **ansible.builtin.shell**
41+
42+
```yaml
43+
ansible.builtin.shell: |
44+
export DEBIAN_FRONTEND=noninteractive
45+
apt-get update
46+
apt-get install -y software-properties-common gnupg gnupg2
47+
add-apt-repository -y ppa:deadsnakes/ppa
48+
apt-get update
49+
apt-get install -y gettext python3.11 python3.11-venv python3.11-dev graphviz fonts-nanum
50+
```
51+
52+
* **ansible.builtin.command**
53+
54+
```yaml
55+
ansible.builtin.command: "bash {{ zuul_doc_path }}/build-translated-lang.sh ko_KR"
56+
args:
57+
chdir: "{{ zuul_doc_path }}"
58+
```
59+
작성한 명령을 실행하는 모듈 2가지입니다.
60+
61+
유사한 모듈이지만 차이가 있습니다.
62+
63+
![command synopsis](https://github.com/user-attachments/assets/3d4b712e-36b7-4f99-ae6d-4c3d922b476e)
64+
65+
66+
ansible.builtin.command의 Synopsis입니다.
67+
68+
ansible.builtin.shell과 달리 shell을 거치지 않고 프로그램이 실행돼서 | 기호를 통한 연속적인 명령 수행이 불가능하다는 차이점이 있습니다.
69+
70+
연속적인 명령이 필요한 파이썬 환경설정을 ansible.builtin.shell로 해결하고
71+
72+
build-translated-lang.sh 스크립트를 실행하는 부분은 ansible.builtin.command로 해결합니다.
73+
74+
* **ansible.builtin.git**
75+
76+
```yaml
77+
ansible.builtin.git:
78+
repo: '[https://opendev.org/zuul/zuul.git](https://opendev.org/zuul/zuul.git)'
79+
dest: "{{ ansible_user_dir }}/zuul-repo"
80+
```
81+
82+
Zuul repoistory를 클론해오는 ansible.builtin.git 모듈입니다. repo와 dest parameter를 꼭 포함해야합니다.
83+
84+
repo parameter에 git repository의 git, SSH, 혹은 HTTP(S) 주소를
85+
86+
dest parameter에 저장할 위치를 입력합니다.
87+
88+
* **ansible.builtin.copy**
89+
90+
```yaml
91+
ansible.builtin.copy:
92+
src: "{{ zuul.project.src_dir }}/l10n-artifact/build-translated-lang.sh"
93+
dest: "{{ zuul_doc_path }}/build-translated-lang.sh"
94+
mode: '0755'
95+
remote_src: yes
96+
```
97+
98+
```yaml
99+
ansible.builtin.copy:
100+
src: "{{ zuul.project.src_dir }}/l10n-artifact/ko_KR"
101+
dest: "{{ zuul_doc_path }}/source/locale/"
102+
remote_src: yes
103+
```
104+
local 혹은 remote머신의 파일을 remote머신으로 복사하는 ansible.builtin.copy 모듈입니다.
105+
106+
여기서 local은 Zuul 메인 서버가 기준입니다.
107+
108+
따라서 두 경우 모두 remote_src parameter를 yes로 수정해서 복사합니다.
109+
110+
또한 dest의 경로가 현재 존재하지 않는 경우 실패하는 점을 주의해야합니다.
111+
112+
그리고 src가 파일이면 dest도 파일이어야하고
113+
114+
src가 디렉터리면 dest도 디렉터리여야합니다.
115+
116+
* **ansible.builtin.file**
117+
118+
```yaml
119+
ansible.builtin.file:
120+
path: "{{ zuul_doc_path }}/source/locale"
121+
state: directory
122+
```
123+
124+
파일, 디렉터리를 수정하는 ansible.builtin.file 모듈입니다.
125+
126+
위에서 설명한 ansible.builtin.copy모듈의 dest경로 지정을 위해 사용합니다.
127+
128+
path parameter에 원하는 디렉터리의 경로를
129+
130+
state에 디렉터리를 입력해서 path에 작성한 경로를 모두 생성합니다.
131+
132+
133+
* **ansible.posix.synchronize**
134+
135+
```yaml
136+
ansible.posix.synchronize:
137+
src: "{{ zuul_doc_path }}/build/html/ko_KR/"
138+
dest: "{{ zuul.executor.log_root }}/html_docs/"
139+
mode: pull
140+
```
141+
142+
ansible.posix.synchronize모듈은 리눅스의 파일 동기화 도구인 rsync의 wrapper입니다.
143+
144+
mode parameter에 pull을 전달해서 remote머신의 src 디렉터리를 local머신의 dest 디렉터리로 가져옵니다.
145+
146+
위에서 사용한 local to remote 복사모듈인 ansible.builtin.copy의 반대기능을 하는
147+
ansible.builtin.fetch 모듈도 ansible에 있지만 fetch모듈은 파일 전송 가능한점을 개선하기 위해
148+
synchronize모듈을 사용합니다.
149+
150+
* **zuul_return**
151+
152+
```yaml
153+
zuul_return:
154+
data:
155+
zuul:
156+
artifacts:
157+
- name: "Korean Documentation (HTML)"
158+
url: "html_docs/index.html"
159+
160+
161+
zuul_return 모듈은 Zuul 환경에서 사용되는 전용 ansible 모듈입니다.
162+
163+
해당 모듈을 사용해서 Zuul 웹 대시보드의 artifacts에 빌드된 HTML파일을 연결합니다.
164+
165+
166+
![dashboard artifacts](https://github.com/user-attachments/assets/9fe5b3d8-9965-4072-b1e7-e3c85f544c58)
167+

0 commit comments

Comments
 (0)