Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
joohanhong
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
JooHan Hong
joohanhong
Commits
a9e02377
Commit
a9e02377
authored
4 years ago
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ansible, 2021-03-08, update13
parent
8c750e81
Pipeline
#5122
passed with stages
in 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
1 deletion
+117
-1
README.md
ANSIBLE/WEB/Config/README.md
+116
-0
README.md
ANSIBLE/WEB/README.md
+1
-1
No files found.
ANSIBLE/WEB/Config/README.md
0 → 100644
View file @
a9e02377
[

](https://www.hongsnet.net)
# Ansible의 Jinja2 템플릿을 이용한 Nginx 설정 배포
> Nginx 설정배포를 자동화 할 수 있다.
## 배포 조건
-
각 서버마다 로그기록 기준은
**IP 주소의 끝자리**
이다(eg, 123.123.123.
**123**
). 즉, 만약
`일괄배포로 수행`
할 시 로그서버에서 중복된 내역 및 로그가 누락될 수 있는 이슈가 있다.
-
default.conf 의 설정에 FQDN 서비스도메인이 100개라고 가정해보자.
-
Inventory 파일에
`mip_num`
이라는 호스트 변수를 추가하여, 이를 변수화하여 배포한다.
## Nginx default.conf 파일의 Review
```
bash
server
{
#서비스명
listen 80
;
server_name FQDN
;
access_log /var/log/nginx/서비스명-
{{
mip_num
}}
.log weblog
;
root /www/서비스명
;
include /etc/nginx/public_params
;
location ~
\.
php
$
{
fastcgi_pass 127.0.0.1:9000
;
fastcgi_index index.php
;
include /etc/nginx/fastcgi_params
;
}
}
...중략
```
## Inventory 설정
```
bash
# cat hosts
[
ALL_HOSTS]
172.16.0.100
managed_ip
=
172.16.0.100
des
=
"2020-12-03"
[
ALL_HOSTS_OK]
```
대상 호스트는 172.16.0.100이며, 추가는 2020-12-03에 수행한다. 참고적으로
**ALL_HOSTS_OK**
호스트 그룹은 작업이 완료된 호스트의 history를 위한 그룹이다.
## Host Variables 설정
```
bash
# cat host_vars/172.16.0.100
ansible_ssh_host: 172.16.0.100
ansible_ssh_port: SSH_포트번호
ansible_ssh_user: 사용자 아이디
ansible_ssh_pass:
"사용자 패스워드"
ansible_become:
yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass:
"!root_패스워드"
ansible_python_interpreter: python2.7
```
## Playbook 설정
```python
---
-
name: Nginx Config File COPY Playbook
hosts: ALL_HOSTS
vars:
time: "{{lookup('pipe','date
\"
+%Y%m%d
\"
')}}"
tasks:
-
name: /etc/nginx/conf.d/default.conf file backup copy check
stat:
path: /etc/nginx/conf.d/default.conf_{{ time }}
register: default_conf_backup
- name: /etc/nginx/conf.d/default.conf backup
command: cp -rf /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf_{{ time }}
when: default_conf_backup.stat.exists == False
- name: Local Directory Create
local_action: command mkdir -p NGINX_REWRITE/{{ time }}/{{ managed_ip }}
- name: /etc/nginx/conf.d/default.conf configuration template
template: src=templates/default.conf.j2 dest=/etc/nginx/conf.d/default.conf mode=0644
register: default_conf
- name: Nginx Configure file fetch
fetch:
src: "{{ item }}"
dest: NGINX_REWRITE/{{ time }}/{{ managed_ip }}/
flat: yes
with_items:
['/etc/nginx/conf.d/default.conf']
- name: Nginx Daemon Reload
service:
name: nginx
state: reloaded
enabled: yes
```
`Nginx 설정`에 대한 Playbook 분석
* [ ] 위의 Playbook은 미리 사전에 Nginx의 default.conf 파일을 Fetch해왔고, 수정했다고 가정한다.
* [ ] 큰 틀에서는 기존 설정을 백업하고, 미리 약속된 설정을 배포하는데 유용하다.
* [ ] 설정 적용이 완료되면, Nginx 데몬은 Reload 된다. 즉, 서비스에 영향을 받는다.
## playbook 실행
```
bash
# ansible-playbook -i hosts nginx_deploy.yml
```
This diff is collapsed.
Click to expand it.
ANSIBLE/WEB/README.md
View file @
a9e02377
...
...
@@ -9,4 +9,4 @@
| NO | ITEM | Content | 비고 |
| ------ | ------ | ------ | ------ |
| 1 | Nginx Install |
[
GO
](
./Nginx/
)
| |
| 2 |
OS Package Installing (apt) |
[
GO
](
./APT
/
)
| |
| 2 |
Nginx Config Deploy |
[
GO
](
./Config
/
)
| |
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment