간단한(?) Ping 테스트.
- inventory 파일 정보
[workers]
worker1 ansible_host=192.168.0.12 ansible_user=root
worker2 ansible_host=192.168.0.14 ansible_user=root
- ping을 쏴보자. (-m 옵션은 module 이라는 의미)
ansible workers -m ping
당연히 될줄 알았으나 Error 발생
worker1 | FAILED! => {
"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}
worker2 | FAILED! => {
"msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"
}
sshpass 프로그램이 없다고 하길래 sshpass 프로그램을 설치했다.
apt install sshpass.
그리고 다시 시도!. 그리고 다시 Error
worker1 | FAILED! => {
"changed": false,
"module_stderr": "Shared connection to 192.168.0.12 closed.\r\n",
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n",
"msg": "MODULE FAILURE",
"rc": 127
}
python 이 없다고 나옴. 생각해보니 master 에 ansible 만 설치했지 다른 노드에는 아무것도 안한 상태였다. 그래서 각각의 노드에 python 을 설치했다. (apt install python)
그리고 나서 다시 했더니 다음과 같은 Error 가 나온다.
worker1 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.0.12: Permission denied (publickey,password).\r\n",
"unreachable": true
}
worker2 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: root@192.168.0.14: Permission denied (publickey,password).\r\n",
"unreachable": true
}
흠... 패스워드 문제인것 같아서 옵션을 줘보고 실행을 해봤다.
ansible all -m ping -k
-k : 이 옵션은 실행시에 password 를 물어보도록 하는 옵션이다.
이렇게 실행을 했더니 정상적으로 실행이 되었다.
root@myserver-001:~# ansible all -m ping -k
SSH password:
worker1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
worker2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
728x90
반응형
'Development > Ansible' 카테고리의 다른 글
Ansible Inventory 파일 (0) | 2021.11.12 |
---|