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
ac9a98d0
Commit
ac9a98d0
authored
Mar 08, 2021
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ansible, 2021-03-08, update10
parent
0c7bfb7e
Pipeline
#5119
passed with stages
in 2 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
+106
-0
README.md
ANSIBLE/INFRA/DNS_RESOLVER/README.md
+106
-0
No files found.
ANSIBLE/INFRA/DNS_RESOLVER/README.md
0 → 100644
View file @
ac9a98d0
[
![logo
](
https://www.hongsnet.net/images/logo.gif
)
](https://www.hongsnet.net)
# Ansible의 jinja2 템플릿을 이용한 DNS Resolver 설정
> DNS Resolver 설정을 자동화할 수 있다.
## 주요 기능
-
templates/resolv.conf.j2 파일을 이용해 변수에 맞게 DNS Resolver 설정을 수행할 수 있다.
-
DNS Resolver는 설정즉시 반영되기 때문에 설정 후 dig 명령을 통해 제대로 Resolving 되는 지 확인한다.
## 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: DNS Resolver Deploy Playbook
hosts: ALL_HOSTS
vars:
time: "{{lookup('pipe','date
\"
+%Y%m%d_%H%M
\"
')}}"
dns_resolver1: "XXX.XXX.XXX.1"
dns_resolver2: "XXX.XXX.XXX.2"
environment:
LANG: ko_KR.UTF-8
tasks:
-
name: /etc/resolv.conf_{{ time }} file check
stat:
path: /etc/resolv.conf_{{ time }}
register: resolv_backup
-
name: /etc/resolv.conf_{{ time }} file backup
command: cp -rf /etc/resolv.conf /etc/resolv.conf_{{ time }}
when: resolv_backup.stat.exists == False
ignore_errors: True
-
name: /etc/resolv.conf deploy
template: src=templates/resolv.conf.j2 dest=/etc/resolv.conf mode=0644
-
name: dig command Result
shell: dig naver.com
register: dig_result
-
debug: var=dig_result
-
name: Local Directory Create
local_action: command mkdir -p DIG_CHECK/{{ managed_ip }}
-
name: DNS Resolver Check Execute Result
local_action: copy content={{ dig_result.stdout }} dest=DIG_CHECK/{{ managed_ip }}/{{ managed_ip }}_dig.txt
-
name: Local Directory Create GIT
local_action: command mkdir -p /mnt/d/GIT/system_engineer/Documents/SERVICE/DNS-RESOLVER/WITNESS/{{ managed_ip }}
-
name: Local Result Git Repository Copy from dig command
local_action: command cp -rf DIG_CHECK/{{ managed_ip }}/{{ managed_ip }}_dig.txt /mnt/d/GIT/system_engineer/Documents/SERVICE/DNS-RESOLVER/WITNESS/{{ managed_ip }}/
```
jinja2 템플릿 내역은 다음과 같다. 참고적으로 핵심적인 내역만은 명시한다.
```
bash
# cat templates/resolv.conf.j2
nameserver {{ dns_resolver1 }}
nameserver {{ dns_resolver2 }}
```
`DNS Resolver 배포`에 대한 Playbook 분석
* [ ] dns_resolver1/2 에 대한 변수 값이 원격 호스트에 설정된다.
* [ ] 적용 후 dig 명령을 쿼리하여, 로컬 시스템(PC 또는 서버)에 증적을 기록한다.
* [ ] dig 명령의 결과는 각 호스트별로 로컬에 파일로 기록된다.
## playbook 실행
```
bash
# ansible-playbook -i hosts dns_resolver.yml
```
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