목적

- myserver에서 forest-server1 ~ forest-server3에 있는 /var/log/forest 폴더를 압축하여 가져오기

 

 


방법 1. ansible

 

Archive 1

$ ansible -m archive -a "path=/var/log/forest dest=/tmp/forest.tar format=tar" -i /etc/inventory.ini forest-server

  • 모든 host의 파일명이 forest.tar로 동일하여 수집 시 구분이 어려움

Archive 2

$ ansible -m archive -a "path=/var/log/forest dest=/tmp/forest-log-{{inventory_hostname}}.tar format=tar" -i /etc/inventory.ini forest-server

  • 파일명에 hostname을 넣어 구분
  • 생성파일 : /tmp/forest-log-forest-server1.tar
  • ansible’s inventory_hostname is a built-in variable.

 

Copy 1

$ ansible -m copy -a "src=/tmp/forest-log-{{inventory_hostname}}.tar dest=/root/ansible_tmp/log/" -i /etc/inventory.ini forest-server

  • copy 모듈은 로컬에서 원격지로 파일을 복사할 경우에 사용
  • ansible’s inventory_hostname is a built-in variable.

 

Copy 2

$ ansible -m fetch -a "src=/tmp/forest-log-{{ansible_hostname}}.tar dest=/root/ansible_tmp/log/ flat=yes" -i /etc/inventory.ini forest-server

  • 원격지에서 로컬으로 파일을 가지고 올 경우 fetch 모듈 사용
  • 'flat=yes' 옵션이 없으면 호스트네임 폴더 아래 소스 파일의 폴더 구조까지 복사 됨.  /root/ansible_tmp/log/kolla-controller01/tmp/kolla-log-kolla-controller01.tar
  • 'flat=yes' 옵션을 넣으면 파일만 복사 됨. /root/ansible_tmp/log/kolla-log-kolla-controller01.tar

 

 

 

 


 

방법 2. ansible-playbook

 

여러 명령을 하나의 playbook으로 작성하여 한 번에 실행

 

(1) playbook 작성

log_archive_pull.yaml
--
- name: Ansible Log Archive
  hosts: forest-server
  tasks:
    - name: Archive forest Log!
      archive:
        path: /var/log/forest
        dest: /tmp/forest-log-{{ansible_hostname}}.tar
        format: tar
    - name: Get Log Files!
      fetch:
        src: /tmp/forest-log-{{ansible_hostname}}.tar
        dest: /root/ansible_tmp/log/
        flat: yes

 

(2) playbook 실행

# root@kolla-deploy:~/ansible_tmp# ansible-playbook log_archive_pull.yml -i /etc/inventory.ini

 

'Ansible' 카테고리의 다른 글

[Ansible] 내가 쓰는 Ansible  (0) 2020.11.10

- 오픈 소스 소프트웨어 프로비저닝, 구성 관리, 애플리케이션 전개 도구

- 2015년에 레드햇이 인수

- ansible-playbook 공부 필요

 

 

 

1. ping 

$ ansible -m ping all inventory/forest/inventory.ini

 

 

2. shell

$ ansible -m shell -a 'mkdir /etc/docker/ ' all -i inventory/forest/inventory.ini

 

 

3. yum

$ ansible -m yum -a 'name="docker-ce" state=latest' -i inventory/forest/inventory.ini all

$ ansible -m yum -a 'name="*" state=latest' -i inventory/kma-for-upgrade2/inventory.ini all

 

 

4. copy

$ ansible -m copy -a 'src=/etc/yum.repos.d/docker-ce.repo dest=/etc/yum.repos.d/docker-ce.repo' all -i inventory/forest/inventory.ini

 

 

 

 

 

* 참고 사이트

docs.ansible.com/ansible/latest/cli/ansible.html

 

 

[Ansible] Solution Guide V0.4_20181204.pdf
0.65MB

 

 

'Ansible' 카테고리의 다른 글

[Ansible-playbook] 다른 서버들의 Log 압축 후 수집  (0) 2021.04.29

+ Recent posts