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
c90df8f6
Commit
c90df8f6
authored
Mar 08, 2021
by
JooHan Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ansible, 2021-03-08, update8
parent
2de06aa8
Pipeline
#5117
passed with stages
in 2 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
README.me
ANSIBLE/INFRA/NTP/README.me
+117
-0
No files found.
ANSIBLE/INFRA/NTP/README.me
0 → 100644
View file @
c90df8f6
[![logo](https://www.hongsnet.net/images/logo.gif)](https://www.hongsnet.net)
# Ansible의 jinja2 템플릿을 이용한 NTP 클라이언트 설정
> NTP 설정을 자동화할 수 있다.
## 주요 기능
- templates/ntp.conf.j2 파일을 이용해 변수에 맞게 NTP 설정을 수행할 수 있다.
## 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: NTP Client Deploy
hosts: ALL_HOSTS
vars:
ntp_server1: "XXX.XXX.XXX.1"
ntp_server2: "XXX.XXX.XXx.2
tasks:
- name: Install a list of packages
apt:
pkg:
- ntp
update_cache: yes
- name: ntp.conf configuration
template: src=templates/ntp.conf.j2 dest=/etc/ntp.conf mode=0644
- name: ntpd Daemon Restart
service:
name: ntp
state: restarted
enabled: yes
```
jinja2 템플릿 내역은 다음과 같다. 참고적으로 핵심적인 내역만은 명시한다.
```bash
# cat templates/ntp.conf.j2
...중략
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server {{ ntp_server1 }} iburst
server {{ ntp_server2 }} iburst
```
`NTP 클라이언트 배포`에 대한 Playbook 분석
* [ ] ntp_server1/2 에 대한 변수 값이 원격 호스트에 설정된다.
* [ ] 추가적으로 아래와 같이 ntpq 명령을 쿼리하는 Playbook과 같이 사용하면 된다.
* [ ] ntpq 명령의 결과는 각 호스트별로 로컬에 파일로 기록된다.
## playbook 실행
```bash
# ansible-playbook -i hosts ntp_deploy.yml
```
## ntpq 명령의 쿼리결과 수집 Playbook
```python
---
- name: ntpq -p command Result
hosts: ALL_HOSTS
vars:
time: "{{lookup('pipe','date \"+%Y-%m-%d %H:%M:%S\"')}}"
tasks:
- name: ntpq command Result
shell: ntpq -p; echo; date; echo "Deploy Server Time => {{ time }}"
register: ntpq_result
- debug: var=ntpq_result
- name: Local Directory Create
local_action: command mkdir -p NTPQ_CHECK/{{ managed_ip }}
- name: TIME Check Execute Result
local_action: copy content={{ ntpq_result.stdout }} dest=NTPQ_CHECK/{{ managed_ip }}/{{ managed_ip }}_ntpq.txt
```
```bash
# ansible-playbook -i hosts ntpq_check.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