[ansible] playbook 작성/실행 - 실습1
- IT2/ansible
- 2023. 2. 15. 07:39
반응형
ansible.cfg 설정값
[defaults] inventory = ./inventory remote_user = ansible ask_pass = false [privilege_escalation] #become = true #become_method = sudo #become_user = root #become_ask_pass = true |
지침
1. web 호스트 그룹 대상으로 수행
2. web_install.yml 플레이북 생성
3. yum 모듈을 사용하여 httpd 패키지 설치
4. copy 모듈을 사용하여 로컬 내 /etc/ansible/data/index.html 파일을 각 관리 호스트(webserver1, webserver2)의 /var/www/html/index.html로 복사
5. service 모듈을 사용하여 httpd 서비스 시작 및 활성화
playbook 작성
[ansible@ansible playbook]$ cat web_install.yml --- - name: Install and start Apache HTTPD become: yes hosts: web tasks: - name: httpd package is present yum: name: httpd state: present - name: correct index.html is present copy: src: /etc/ansible/data/index.html dest: /var/www/html/index.html - name: httpd is started service: name: httpd state: started enabled: true ... |
playbook 구문 체크
[ansible@ansible playbook]$ ansible-playbook --syntax-check web_install.yml playbook: web_install.yml |
playbook 실행
[ansible@ansible playbook]$ ansible-playbook web_install.yml PLAY [Install and Start Apache Httpd] ***************************************************************** TASK [Gathering Facts] ******************************************************************************** ok: [webserver1] ok: [webserver2] TASK [httpd package is present] *********************************************************************** changed: [webserver2] changed: [webserver1] TASK [correct index.html is present] ****************************************************************** changed: [webserver2] changed: [webserver1] TASK [httpd is started] ******************************************************************************* changed: [webserver1] changed: [webserver2] PLAY RECAP ******************************************************************************************** webserver1 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 webserver2 : ok=4 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 |
playbook 실행 결과 테스트
[ansible@ansible playbook]$ curl http://webserver1 WEB Service Test [ansible@ansible playbook]$ curl http://webserver2 WEB Service Test |
반응형
'IT2 > ansible' 카테고리의 다른 글
[ansible] playbook 개념/작성/예시 (0) | 2023.02.12 |
---|---|
[ansible] yaml(yml)을 위한 vi(vim) 꿀팁 설정 (0) | 2023.02.11 |
[ansible] inventory(인벤토리) 작성법-① (0) | 2023.01.29 |
[ansible] playbook 작성/실행 - SSH Public key 배포 (ssh-key 교환 방법) (0) | 2023.01.29 |
[ansible] ping 테스트 실패 (Failed to connect to the host via ssh: Permission denied) 해결 방법 (0) | 2023.01.28 |