- 변수
- "{{ 변수명 }}" 으로 변수를 선언 할수 있다.
---
- name: ping test
hosts: all
gather_facts: false
tasks:
- name: ping
ping:
- name: 작업을 설명하는 내용 작성 (생략가능)
- hosts: 작업을 실행할 곳 (inventory 내의 hosts)
- gather_facts: 작업시작전 host 자원정보 사전 수집이라고 보면될듯(default로 동작하지만 false로 실행을 많이 하는것 같음)
- tasks: 작업목록
- 모든 tasks는 name을 가지고 있어야함
- 하나의 task는 하나의 모듈만 실행가능
- 여러개의 tasks로 구성이 가능하며 순차적으로 실행됨
---
- hosts: all
remote_user: root
tasks:
- name: store file to remote server
copy:
src: "/tmp/{{ item }}"
dest: /tmp/
with_items:
- a.txt
- b.txt
- c.txt
- copy 모듈
- src: 복사할 파일의 출발지 경로 및 파일명
- dest: 복사할 파일의 목적지 경로 및 파일명
- backup: 기존파일을 백업
- owner: 파일의 소유자 권한 수정
- group: 파일의 그룹 권한 수정
- mode: 파일의 퍼미션 수정
- with_items 모듈
- 여러가지 파일의 copy가 필요한 경우 사용
- name: Test Fetch
hosts: {{ RemoteServer }}
remote_user: ubuntu
tasks:
- name: Copying files from remote server
fetch:
src: "/path/to/RemoteServerFilePath"
dest: "/path/to/localhostPath"
- fetch 모듈
- src: 복사할 파일의 remote server 경로 및 파일명
- dest: 복사할 파일의 로컬 경로
- name: execute a shell script on a remote server
script: /tmp/ABC.sh
- script 모듈
- shell script 실행
'프로그래밍 > Ansible' 카테고리의 다른 글
Inventory (0) | 2022.01.05 |
---|---|
ansible.cfg 설정 (0) | 2022.01.05 |
Ansible-Playbook 명령어 옵션 정리 (0) | 2022.01.05 |