728x90
반응형
1. Command, System 명령어
# 파일 체크
- name: Check /etc/zabbix/zabbix_agent.d/server.conf file
stat:
path: /etc/zabbix/zabbix_agent.d/server.conf
register: server_conf_stat_1
# 파일 수정
- name: Amend /etc/zabbix/zabbix_agent.d/server.conf file
shell: sed -i 's/ServerActive=.*/ServerActive=10.10.10.1/g' /etc/zabbix/zabbix_agent.conf.d/server.conf
when: server_conf_stat_1.stat.exist == True
# 스크립트 실행
- name: Run a script with arguments
script: /some/local/script.sh --some-argument 1234
# 스크립트 조건 실행
- name: Run a script only if file.txt does not exist on the remote node
script: /some/local/create_file.sh --some-argument 1234
args:
creates: /the/created/file.txt
# 스크립트 조건 실행2
- name: Run a script only if file.txt exist on the remote node
script: /some/local/remove_file.sh --some-argument 1234
args:
creates: /the/removed/file.txt
# Python 스크립트 실행
- name: Run a script using an executable in a system path
script: /some/local/script.py
args:
executable: python3
2. File 관리
# 파일 체크용 stat 생성
- name: Check the directory or file
stat:
path: /tmp/test.sh
register: check_file
# stat 활용 방법
- name: If the file does not exist, create the file
file:
path: /tmp/test.sh
state: touch
## 둘다 사용 가능
when: not check_file.stat.exist
when: check_file.stat == False
# 파일 여러 개 복사
- name: Copy many files
become: yes
copy:
# Default 경로: /etc/ansible/roles/[role 이름]/files
src: Linux/{{ item }}
dest: /tmp/{{ item }}
with_items:
- tets.sh
- test2.sh
- test3.sh
# 파일 생성 시 권한 부여
- name: Create file with permission
file:
path: /tmp/test.sh
state: touch
owner: root
group: root
mode: 0644
3. Service 관리
# 서비스 시작(service zabbix-agent start)
- name: start zabbix-agent service
service:
name: zabbix-agent
state: started
# 서비스 중지(service zabbix-agent stop)
- name: stop zabbix-agent service
service:
name: zabbix-agent
state: stopped
# 서비스 재 시작(service zabbix-agent restart)
- name: restart zabbix-agent service
service:
name: zabbix-agent
state: restarted
# 서비스 Enable(systemctl enable zabbix-agent)
- name: enable zabbix-agent service
service:
name: zabbix-agent
enabled: yes
## Systemd
# 서비스 시작(systemctl start zabbix-agent)
- name: start zabbix-agent service
systemd:
name: zabbix-agent
state: started
# 서비스 중지(systemctl stop zabbix-agent)
- name: stop zabbix-agent service
systemd:
name: zabbix-agent
state: stopped
# 서비스 재 시작(systemctl restart zabbix-agent)
- name: restart zabbix-agent service
systemd:
name: zabbix-agent
state: restarted
# 서비스 Enable(systemctl enable zabbix-agent)
- name: enable zabbix-agent service it is not masked
systemd:
name: zabbix-agent
enabled: yes
masked: no
728x90
반응형
'Ansible' 카테고리의 다른 글
Ansible Zabbix 운영 (0) | 2021.04.29 |
---|---|
Ansible Windows 서버 파일 배포 (2) | 2021.01.30 |
Ansible task 생성 및 실행 (0) | 2020.10.30 |
Ansible 설치 및 실행 (0) | 2020.10.30 |
Ansible 기본 명령어 (0) | 2020.10.25 |