반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- swapon
- 프로세스
- docker image
- docker network
- 리다이렉션
- M365필터
- HTTPD
- ssh
- MSBing
- journalctl
- Kubernetes
- 날짜변경
- pvcreate
- newbingai
- chmod
- docker
- 랜카드인식불량
- tar
- 엑셀파일명변경
- 같은폴더
- mount
- lvcreate
- yum
- chatGPT
- vgcreate
- ansible
- nmcli
- vagrant kubernetes
- permission
- firewalld
Archives
- Today
- Total
becool
20210727 (화) ad-hoc 명령어 및 playbook 기초 본문
반응형
9:33 review
ansible 모듈 : https://docs.ansible.com/ansible-core/devel/collections/ansible/builtin/index.html#plugins-in-ansible-builtin
ansible ad-hoc 명령어
ansible [pattern] -m MODULE [-a ARGUMENT]
※ shell 모듈은 멱등성을 지원하지 않고, 결과값에 지속적으로 CHANGED로 보여지게되므로 상황에 맞게 사용.
[user@ansible-server work]$ ansible all -m shell -a "yum list |grep python2" [user@ansible-server work]$ ansible webservers -m yum -a "name=httpd state=present" → 1회차 실행 192.168.56.11 | CHANGED => { → 명령 성공, changed true (httpd 패키지 설치) "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": true, [user@ansible-server work]$ ansible webservers -m yum -a "name=httpd state=present" → 2회차 실행 192.168.56.11 | SUCCESS => { → 명령 성공, changed false (이미 설치되었으므로) "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, [user@ansible-server work]$ ansible all -m user -a "name=test" → 생성 [user@ansible-server work]$ ansible all -m user -a "name=test state=absent" →삭제 [user@ansible-server work]$ ansible all -m shell -a "tail /etc/passwd" → 확인 [user@ansible-server work]$ ansible webservers -m service -a "name=httpd state=started" [user@ansible-server work]$ ansible webservers -m service -a "name=httpd state=started" >> ~/fileA [user@ansible-server work]$ ansible webservers -m service -a "name=httpd state=stopped" >> ~/fileA [user@ansible-server work]$ ansible localhost -m shell -a "echo test > ~/work/aaa" 리다이렉션은 shell 모듈로 사용 가능 |
Ansible Playbook
VI 에디터 yaml편의옵션
~./vimrc syntax on autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab autoindent ※ 파일타입 : yaml에 한해서 ts : 스페이스 2칸, sts : 지울때 2칸, sw : tab 확장, autoindent |
httpd 실행 테스트
[user@ansible-server work]$ vim install_httpd.yml --- - name : "Install Apache Webserver" hosts : all tasks : - name : Install latest Apache Webserver (YUM) yum : name : httpd state : latest [user@ansible-server work]$ ansible-playbook --syntax-check install_httpd.yml → 문법체크 playbook: install_httpd.yml [user@ansible-server work]$ ansible-playbook install_httpd.yml PLAY [Install Apache Webserver] **************************************************************************************** TASK [Gathering Facts] ************************************************************************************************* ok: [192.168.56.12] ok: [192.168.56.13] ok: [192.168.56.11] TASK [Install latest Apache Webserver (YUM)] *************************************************************************** ok: [192.168.56.11] changed: [192.168.56.12] changed: [192.168.56.13] PLAY RECAP ************************************************************************************************************* 192.168.56.11 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.56.12 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.56.13 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [user@ansible-server work]$ vim uninstall_httpd.yml --- - name : "Uninstall Apache Webserver" hosts : all tasks : - name : Uninstall Apache Webserver (YUM) yum : name : httpd state : absent [user@ansible-server work]$ ansible-playbook --syntax-check uninstall_httpd.yml playbook: uninstall_httpd.yml [user@ansible-server work]$ ansible-playbook -i inventory2/hosts5 uninstall_httpd.yml PLAY [Uninstall Apache Webserver] ************************************************************************************** TASK [Gathering Facts] ************************************************************************************************* ok: [192.168.56.12] ok: [192.168.56.11] ok: [192.168.56.13] TASK [Uninstall Apache Webserver (YUM)] ******************************************************************************** changed: [192.168.56.11] changed: [192.168.56.12] changed: [192.168.56.13] PLAY RECAP ************************************************************************************************************* 192.168.56.11 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.56.12 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.168.56.13 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
728x90
'ansible' 카테고리의 다른 글
20210730 (금) playbook 연습장 (0) | 2021.07.30 |
---|---|
20210730 (금) ansible 조건문, 블록, 핸들러 (0) | 2021.07.30 |
20210729 (목) ansible 변수, 반복문, 조건문 (0) | 2021.07.29 |
20210728 (수) playbook 변수 실습 (0) | 2021.07.28 |
20210726 (월) ansible 설치 (0) | 2021.07.26 |
Comments