1.6. 첫 번째 플레이북 생성
다음 절차에 따라 호스트를 ping하고 "Hello world" 메시지를 출력하는 플레이북을 생성합니다.
프로세스
다음 콘텐츠를 사용하여
ansible_quickstart
디렉터리에playbook.yaml
이라는 파일을 생성합니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - name: My first play hosts: myhosts tasks: - name: Ping my hosts ansible.builtin.ping: - name: Print message ansible.builtin.debug: msg: Hello world
- name: My first play hosts: myhosts tasks: - name: Ping my hosts ansible.builtin.ping: - name: Print message ansible.builtin.debug: msg: Hello world
다음 명령을 사용하여 플레이북을 실행합니다.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ansible-playbook -i inventory.ini playbook.yaml
ansible-playbook -i inventory.ini playbook.yaml
- Ansible은 다음 출력을 반환합니다.
PLAY [My first play] **************************************************************************** TASK [Gathering Facts] ************************************************************************** ok: [192.0.2.50] ok: [192.0.2.51] ok: [192.0.2.52] TASK [Ping my hosts] **************************************************************************** ok: [192.0.2.50] ok: [192.0.2.51] ok: [192.0.2.52] TASK [Print message] **************************************************************************** ok: [192.0.2.50] => { "msg": "Hello world" } ok: [192.0.2.51] => { "msg": "Hello world" } ok: [192.0.2.52] => { "msg": "Hello world" } PLAY RECAP ************************************************************************************** 192.0.2.50: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.0.2.51: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 192.0.2.52: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
PLAY [My first play] ****************************************************************************
TASK [Gathering Facts] **************************************************************************
ok: [192.0.2.50]
ok: [192.0.2.51]
ok: [192.0.2.52]
TASK [Ping my hosts] ****************************************************************************
ok: [192.0.2.50]
ok: [192.0.2.51]
ok: [192.0.2.52]
TASK [Print message] ****************************************************************************
ok: [192.0.2.50] => {
"msg": "Hello world"
}
ok: [192.0.2.51] => {
"msg": "Hello world"
}
ok: [192.0.2.52] => {
"msg": "Hello world"
}
PLAY RECAP **************************************************************************************
192.0.2.50: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.0.2.51: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
192.0.2.52: ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
이 출력에서는 다음을 확인할 수 있습니다.
- 플레이 및 각 작업을 지정하는 이름입니다. 항상 플레이북을 쉽게 확인하고 문제를 해결할 수 있는 설명이 포함된 이름을 사용합니다.
- Gather Facts 작업은 암시적으로 실행됩니다. 기본적으로 Ansible은 플레이북에서 사용할 수 있는 인벤토리에 대한 정보를 수집합니다.
-
각 작업의 상태입니다. 각 작업의 상태가
ok
이므로 성공적으로 실행됨을 의미합니다. -
호스트당 플레이북의 모든 작업의 결과를 요약하는 play recap. 이 예제에는 3개의 작업이 있으므로
ok=3
은 각 작업이 성공적으로 실행되었음을 나타냅니다.