IaC/Ansible 이론
Ansible Ad-Hoc 명령 | -m 옵션, -a 옵션, 모듈의 반환 값(return values)
Greta Lee
2021. 7. 28. 12:44
SMALL
Ad-Hoc 명령
ad-hoc 명령은 하나 이상의 관리 노드에 단일 작업을 실행하는 임시 명령입니다. 임시 명령은 거의 반복하지 않는 간단한 작업에 주로 사용합니다.
- 임시 명령의 사용 예
- 서버 재부팅
- 파일 관리
- 패키지 관리
- 사용자 및 그룹 관리
- 서비스 관리
- 팩스 변수 수집
1. Ad-hoc 명령 사용
ansible [pattern] -m [module] -a "[module options]"
- -m : 모듈 이름 지정 (default : command)
- -a : 모듈의 옵션 / 아규먼트
2. Ad-hoc 명령 사용 예
1) 시스템 재부팅
ansible databases -a "/sbin/reboot" -u username -b -K
2) 파일 복사
ansible foo.example.com -m copy -a "src=/etc/hosts dest=/tmp/hosts"
3) 파일 권한 변경
ansible webservers -m file -a "dest=/srv/foo/a.txt mode=600"
4) 파일 소유권 변경
ansible webservers -m file -a "dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory"
5) 파일 삭제
ansible wewbservers -m file -a "dest=/path/to/c state=absent"
6)패키지 설치 (업데이트 X)
ansible webservers -m apt -a "name=acme state=present"
7) 특정 버전 패키지 설치
ansible webservers -m apt -a "name=acme=q:0.96.4-5 state=present"
8) 패키지 제거
ansible webservers -m apt -a "name=acme state=absent"
9) 사용자 생성
ansible all -m user -a "name=foo password=<crypted password here>"
10) 사용자 제거
ansible all -m user -a "name=foo state=absent"
11) 서비스 시작
ansible webservers -m service -a "name=apache2 state=started"
12) 서비스 재시작
ansible webservers -m service -a "name=apache2 state=restarted"
3. 일반적인 모듈의 반환 값 (common return values)
일반적으로 공통으로 사용되는 모듈의 반환 값에 대한 설명입니다. 일반적인 모듈의 반환 값 이외에 모듈의 따라 반환 값은 저마다 다릅니다. 모듈의 반환 값은 아래 모듈의 설명서를 링크를 참조하세요.
https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html
Return Values — Ansible Documentation
Some modules execute command line utilities or are geared for executing commands directly (raw, shell, command, and so on), this field contains ‘return code’ of these utilities. Some modules execute command line utilities or are geared for executing co
docs.ansible.com
SMALL