ansible connect test(with ssh)

ansible을 이용하여 서버 접근

1. 환경준비
    Centos 7.x
    Ansible 

2. env ansible
[root@localhost ~]# vi /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

[testgroup]
192.168.0.156 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxxx

192.168.0.116 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxxx

3. ping test
[root@localhost ansible]# ansible testgroup -m ping
192.168.0.156 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}
192.168.1.116 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.1.116 port 22: Connection timed out",
    "unreachable": true

}

##156번 서버는 fingerprint가 설정되어 있지 않아서
[root@localhost ansible]# ssh 192.168.0.116
The authenticity of host '192.168.0.116 (192.168.0.116)' can't be established.
ECDSA key fingerprint is SHA256:cGCR8RNUA8d6Rj
ECDSA key fingerprint is MD5:c0:e0:ad:cc:96:48:d
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.116' (ECDSA) to the list of known hosts.

root@192.168.0.116's password:

##116번 서버는 아이피 설정이 잘못되었을 경우

##재시도
[root@localhost ansible]# ansible testgroup -m ping
192.168.0.156 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}
192.168.0.116 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"

}








댓글

이 블로그의 인기 게시물

[!] CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/CocoaPods-version.yml Response: URL using bad/illegal format or missing URL

starcraft map

Data Analysis with Superset - boardless chart